Mimic a web surfer ?
jdhunter at ace.bsd.uchicago.edu
Tue Apr 1 16:28:03 CEST 2003
>>>>> "shagshag13" == shagshag13 <shagshag13 at yahoo.fr> writes:
shagshag13> hello, i would like to develop a script which will
shagshag13> mimic a web surfer, that is :
shagshag13> - follow links as a human and thus always come from
shagshag13> previous page (i think there is something to do with
shagshag13> http 'referer' and cookies) - be able to log if
shagshag13> is there anything already existing ? i'm looking for
shagshag13> any tips which will help me to start...
shagshag13> note : this could be used to have "automatic" access
shagshag13> to free webmails not providing pop protocol.
Yes, this is possible. As you say, you generally need to set referer
and or cookies. This can be done with httplib. I often find the best
way to do this is to install a sniffer which monitors traffic on port
80. If you are on linux, you may want to try sniffit. On windows, I
have had luck with proxomitron. With one of these sniffers running,
browse the site you want to mimic and capture all the traffic. Pore
through the logs and figure out how the site wants you to handle
cookies and referers, and then whip up your python version. Here is
an example script using httplib that sets referer and cookie headers
host = 'slashdot.org'
pathn = '/science/01/12/03/1630212.shtml'
h = httplib.HTTP(host)
h.putheader('User-Agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.4) Gecko/20010913')
h.putheader('From', 'marshall at migley.zko.dec.com')
errcode, errmsg, headers = h.getreply()
except socket.error, er:
print 'socket error ', er
hkeys = headers.keys()
#for key in hkeys:
# print key, ' = ', headers.getrawheader(key)
More information about the Python-list