Python 官方文档:入门教程 => 点击学习
只是拿来的文章,留个存档,可不保证能用 使用已有的cookie访问网站 import cookielib, urllib2 ckjar = cookielib.MozillaCookieJar(os.path.join(’C:
只是拿来的文章,留个存档,可不保证能用
import cookielib, urllib2
ckjar = cookielib.MozillaCookieJar(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()
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)
import cookielib, urllib2
cookiejar = cookielib.CookieJar()
urlOpener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
values = {’redirect’:”, ‘email’:'abc@abc.com’,
‘passWord’:'password’, ‘rememberme’:”, ’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
--结束END--
本文标题: Python的cookie处理分享
本文链接: https://lsjlt.com/news/189722.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0