0

Hi everybody.
What is the usage of urljoin?
An example:

>>> from urlparse import urljoin
>>> url = urljoin('http://python.org/','about.html')
>>> url
'http://python.org/about.html'

I think the answer is that when we take a link from here 'http://www.python.org/ for example , it looks like this <a href="/about/>about</a>.
So if i take the href part which is /about/ here and use urljoin to join this string (of course with .html) to the main url which is 'http://python.org/' here. Correct?!

Of course i should delete those / and / from /about/ first.

Edited by Niloofar24

3
Contributors
3
Replies
35
Views
1 Year
Discussion Span
Last Post by Niloofar24
Featured Replies
  • It's a function from standard module urlparse in Python2. You will find mor info and syntax in python docs at the official site Python.org. Follow link -> [Click Here](https://docs.python.org/2/library/urlparse.html) Read More

  • 1
    vegaseat 1,720   1 Year Ago

    An example ... # assume you have this url ... url = "https://www.python.org/downloads/release/python-343/" # the base (scheme + netloc) would be ... base = "https://www.python.org/" # the path would be ... path = "downloads/release/python-343/" # however you want to select one of these paths ... path_list = ["community/", "doc/", "community/jobs/"] … Read More

2

It's a function from standard module urlparse in Python2. You will find mor info and syntax in python docs at the official site Python.org.

Follow link -> Click Here

1

An example ...

# assume you have this url ...
url = "https://www.python.org/downloads/release/python-343/"
# the base (scheme + netloc) would be ...
base = "https://www.python.org/"
# the path would be ...
path = "downloads/release/python-343/"
# however you want to select one of these paths ...
path_list = ["community/", "doc/", "community/jobs/"]

# to create a full url use ...
new_url = urlparse.urljoin(base, path_list[2])
print(new_url)  # https://www.python.org/community/jobs/ 
This question has already been answered. Start a new discussion instead.
Take the time to help us to help you. Please be thoughtful and detailed and be sure to adhere to our posting rules.