Urllib2: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
 
Line 6: Line 6:
pagefile=urllib2.urlopen(request)
pagefile=urllib2.urlopen(request)
realurl = pagefile.geturl()
realurl = pagefile.geturl()
info = pagefile.info()
</source>
</source>



Latest 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()
info = pagefile.info()


Checking a Domain