Impersonating other broswers...

Diez B. Roggisch deetsNOSPAM at web.de
Sat Mar 5 23:39:20 CET 2005


sboyle55 at yahoo.com wrote:

> So I wrote a quick python program (my first ever) that needs to
> download pages off the web.
> 
> I'm using urlopen, and it works fine.  But I'd like to be able to
> change my browser string from "Python-urllib/1.15" to instead
> impersonate Internet Explorer.
> 
> I know this can be done very easily with Perl, so I'm assuming it's
> also easy in Python.  How do I do it?

from the urllib docs:

'''
class URLopener(
[proxies[, **x509]])

 Base class for opening and reading URLs. Unless you need to support opening
objects using schemes other than http:, ftp:, gopher: or file:, you
probably want to use FancyURLopener. 

By default, the URLopener class sends a User-Agent: header of "urllib/VVV",
where VVV is the urllib version number. Applications can define their own
User-Agent: header by subclassing URLopener or FancyURLopener and setting
the instance attribute version to an appropriate string value before the
open() method is called. 


The optional proxies parameter should be a dictionary mapping scheme names
to proxy URLs, where an empty dictionary turns proxies off completely. Its
default value is None, in which case environmental proxy settings will be
used if present, as discussed in the definition of urlopen(), above. 


Additional keyword parameters, collected in x509, are used for
authentication with the https: scheme. The keywords key_file and cert_file
are supported; both are needed to actually retrieve a resource at an https:
URL. 

'''
-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list