Python: confusions with urljoin -


i trying form urls different pieces, , having trouble understanding behavior of method. example:

python 3.x

from urllib.parse import urljoin  >>> urljoin('some', 'thing') 'thing' >>> urljoin('http://some', 'thing') 'http://some/thing' >>> urljoin('http://some/more', 'thing') 'http://some/thing' >>> urljoin('http://some/more/', 'thing') # tad / after 'more' 'http://some/more/thing' urljoin('http://some/more/', '/thing') 'http://some/thing' 

can explain exact behavior of method?

the best way (for me) think of first argument, base page on in browser. second argument url href of anchor on page. result final url directed should click.

>>> urljoin('some', 'thing') 'thing' 

this 1 makes sense give description. though 1 hope base includes scheme , domain.

>>> urljoin('http://some', 'thing') 'http://some/thing' 

if on vhost some, , there anchor <a href='thing'>foo</a> link take http://some/thing

>>> urljoin('http://some/more', 'thing') 'http://some/thing' 

we on some/more here, relative link of thing take /some/thing

>>> urljoin('http://some/more/', 'thing') # tad / after 'more' 'http://some/more/thing' 

here, aren't on some/more, on some/more/ different. now, our relative link take some/more/thing

>>> urljoin('http://some/more/', '/thing') 'http://some/thing' 

and lastly. if on some/more/ , href /thing, linked some/thing.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -