Urllib2: Difference between revisions
No edit summary |
No edit summary |
||
Line 5: | Line 5: | ||
request.add_header("User-Agent", user_agent) | request.add_header("User-Agent", user_agent) | ||
pagefile=urllib2.urlopen(request) | pagefile=urllib2.urlopen(request) | ||
realurl = pagefile.geturl() | |||
</source> | </source> | ||
Revision as of 18:52, 24 March 2009
Making a Request (pretending to be Firefox)
request = urllib2.Request(url)
user_agent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.14) Gecko/20080418 Ubuntu/7.10 (gutsy) Firefox/2.0.0.14"
request.add_header("User-Agent", user_agent)
pagefile=urllib2.urlopen(request)
realurl = pagefile.geturl()