I want to fix some situations about urlparse.urljoin. Using this lib like
urljoin('http://xxxx.yyy/directory/','file.file')
gives me http://xxxx.yyy/directory/file.file but if i don't give slash at last in url like
urljoin('http://xxxx.yyy/directory','file.file')
gives me http://xxxx.yyy/file.file and this distrube me to write auto-collecting program. can any one have solutions to fix this problem. I tried to put slash at last with regex and replace but these are not working properly when url is finished like
http://xxxx.yyy/zzzz/file.file
It's behaving correctly. If you're on http://example.com/index.html
and click a link to two.html
, you end up at http://example.com/two.html
. That's how relative URLs are defined to work.
urljoin
has no way of knowing whether the last component is a directory or not. You could try to guess, perhaps by looking for a .
, and only add the slash if you think it should be there.