Bdfy Bdfy - 1 year ago 123
Python Question

How to join absolute and relative urls?

I have urls:

url1 = ""
url2 = "../../test4/test6.xml"

How to get a absolute url for url2 ?

Answer Source

You should use urlparse.urljoin :

>>> import urlparse
>>> urlparse.urljoin(url1, url2)

With Python 3 urlparse is renamed to urllib.parse:

>>> import urllib.parse
>>> urllib.parse.urljoin(url1, url2)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download