Use existing IE cookie
Diez B. Roggisch
deets at nospam.web.de
Thu Jul 30 17:16:44 CEST 2009
> Hi there,
> Relevant versions: Python 2.5, Vista Home, IE7
> I am trying to scrape a website I have browsed manually in the past,
> and also manually selected my options, and now want python to use my
> existing cookie from the manual browse when downloading data.
> Using: http://code.activestate.com/recipes/80443/ I have found the
> "name" of the relevant cookie, just after reading urllib2 docs, I
> can't see how to "send" or have my python instance use "MY" existing
> Using the following:
> import re
> import urllib2, cookielib
> # set things up for cookies
> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
> reply = urllib2.urlopen('foo.html').read()
> print reply
> This does return data, just default data, not the data from the
> options I set up when manually browsing.
> My sense is that I need "something" in the () part of
> HTTPCookieProcessor() but I have no idea as to what... the docs say
> "cookiejar" but the only code examples I have found are to create a
> cookiejar for the existing Python session, not to use the cookies from
> my prior manual meanderings.
Because this is a completely different beast. You need to find out if and
how to access IE-cookies from python - I guess some win32-road is to be
walked down for that.
Once you get a hold on them, you can build up whatever cookiejar urllib2
More information about the Python-list