I am using CentOS 5.5 and Python.
The following code works perfectly,
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.开发者_运维百科HTTPCookieProcessor(cj))
login_data = urllib.urlencode({'username' : 'myname', 'password' : '123456'})
resp = opener.open('http://www.example.com/signin.html', login_data)
However, I want to save the cookies to /var/www/html/cookies
and load it when I need, so I don't have to sign in every time, just like the browsers do.
How can I save and load the cookies? Thanks a lot!
cookielib
defines a separate FileCookieJar class that has the functionality you're looking for.
精彩评论