MSIE6 Python Question

tutu milas_gi at hotmail.com
Thu May 27 12:18:22 EDT 2004


> > I'm not sure why you need to go through IE, but maybe this will get you into
> > the right direction:
> > 
> > >>> import urllib
> > >>> f = urllib.urlopen('http://www.python.org')

> 
> 
> Sorry. I forgot to mention that I have tried that. The data I want is
> being stripped out when I access the URL via urllib. 


Try something like this:
It may be the site does not like urllib agent so try to pretend you are using IE.
class URLHandler(urllib2.HTTPRedirectHandler, urllib2.HTTPDefaultErrorHandler): 
     pass
agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"
request = urllib2.Request(url)
request.add_header("User-Agent", agent)
opener = urllib2.build_opener(URLHandler())
opener.addheaders = [] # RMK - must clear so we only send our custom User-Agent
htm = opener.open(request)
opener.close() 
htm.read()

Good Look



More information about the Python-list mailing list