It's just an article. It's not guaranteed to be usable if you keep an archive.
- Use existing cookies to access the website
Import cookielib, urllib2
Ckjar = cookielib. cookillacookiejar (OS. Path. Join ('C: \ Documents and Settings \ Tom \ Application Data \ Mozilla \ Firefox \ profiles \ h5m61j1i. default ',
'Cookies.txt '))
Req = urllib2.request (URL, postdata, header)
Req. add_header ('user-agent ',\
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1 )')
Opener = urllib2.build _ opener (urllib2.httpcookieprocessor (ckjar ))
F = opener. Open (req)
Htm = f. Read ()
F. Close ()
- Access the website to obtain the cookie and save it in the cookie file.
Import cookielib, urllib2
Req = urllib2.request (URL, postdata, header)
Req. add_header ('user-agent ',\
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1 )')
Ckjar = cookielib. mozillacookiejar (filename)
Ckproc = urllib2.httpcookieprocessor (ckjar)
Opener = urllib2.build _ opener (ckproc)
F = opener. Open (req)
Htm = f. Read ()
F. Close ()
Ckjar. Save (ignore_discard = true, ignore_expires = true)
- Generate a cookie using the specified parameter and use the cookie to access the website
Import cookielib, urllib2
Cookiejar = cookielib. cookiejar ()
Urlopener = urllib2.build _ opener (urllib2.httpcookieprocessor (cookiejar ))
Values = {'redirect': ", 'email ': 'abc @ abc.com ',
'Password': 'Password', 'memberme': ", 'submit ':' OK, let me in! '}
Data = urllib. urlencode (values)
Request = urllib2.request (URL, data)
Url = urlopener. Open (request)
Print url.info ()
Page = URL. Read ()
Request = urllib2.request (URL)
Url = urlopener. Open (request)
Page = URL. Read ()
Print page