I have the following python script and I would like to send “fake” header information along so that my application acts as if it is firefox. How could I do that?
import urllib, urllib2, cookielib
username = '****'
password = '****'
login_user = urllib.urlencode({'password' : password, 'username' : username})
jar = cookielib.FileCookieJar("cookies")
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))
response = opener.open("http://www.***.com")
response = opener.open("http://www.***.com/login.php")
response = opener.open("http://www.***.com/welcome.php", login_user)
Use the
addheaders()function on youropenerobject.Just add this one line after you create your opener, before you start opening pages:
http://docs.python.org/library/urllib2.html (it’s at the bottom of this document)