【Python学习】Python写爬虫时用到的相对路径和绝对路径--urljoin

使用urlparse.urljoin从相对路径获取绝对路径:

    >>> from urlparse import urljoin  
    >>> urljoin("http://www.asite.com/folder/currentpage.html", "anotherpage.html")  
    'http://www.asite.com/folder/anotherpage.html'  

    >>> urljoin("http://www.asite.com/folder/currentpage.html", "folder2/anotherpage.html")  

    >>> urljoin("http://www.asite.com/folder/currentpage.html", "/folder3/anotherpage.html")  
    'http://www.asite.com/folder3/anotherpage.html'  

    >>> urljoin("http://www.asite.com/folder/currentpage.html", "../finalpage.html")  
    'http://www.asite.com/finalpage.html'  

你可能感兴趣的:(Python)