Looking for a urllib(2) cookie handler

Mark Carter alt.mcarter at gmail.com
Tue Apr 19 08:48:14 EDT 2011


On Apr 19, 12:44 pm, Mark Carter <alt.mcar... at gmail.com> wrote:

> url and say "just use the cookie that I have in Firefox"?

"mechanize" looks kinda like what I want, but i still can't get it to
work properly. So far I have:

import cookielib
import mechanize

cookiefile = "C:\\Users\\$ME\\AppData\\Roaming\\Mozilla\\Firefox\
\Profiles\\zl648qvt.default\\cookies.sqlite"
cookies = mechanize.MozillaCookieJar(filename = cookiefile,
delayload=True)
#cookies = cookielib.MozillaCookieJar()
#cookies = cookielib.MSIECookieJar()
#cookies.load_from_registry()  # finds cookie index file from registry
br = mechanize.Browser()
br.set_cookiejar(cookies)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-
US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
url = "$URL"
r = br.open(url)

#print cj
#opener =
mechanize.build_opener(mechanize.HTTPCookieProcessor(cookies))


html = r.read()
print html

where $ME and $URL are replaced with suitable values. It doesn't
appear to acutally be "using" the cookies.



More information about the Python-list mailing list