Urllib2: Difference between revisions

From XPUB & Lens-Based wiki
(New page: * http://docs.python.org/lib/module-urllib2.html * http://www.voidspace.org.uk/python/articles/urllib2.shtml)
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Making a Request (pretending to be Firefox) ==
<source lang="python">
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()
</source>
== Checking a Domain ==
* http://docs.python.org/lib/module-urllib2.html
* http://docs.python.org/lib/module-urllib2.html
* http://www.voidspace.org.uk/python/articles/urllib2.shtml
* http://www.voidspace.org.uk/python/articles/urllib2.shtml

Latest revision as of 19: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