I am learning python and trying to get the urllib2 geturl() to work. So far, I have the following skeleton, which looks like:
import urllib2
gh=urllib2.urlopen(http://somewebsite.com/).geturl()
print gh
which seems to work fine. However, when I try for example using a url given here, it fails to get me the “final url” (but works on a browser).
I would appreciate any guidance to solve this.
This happens, because you are redirected using javascript, and
urllib2can’t handle javascript. If it is important to handle javascript redirects, use selenium.