发布时间:2019-09-14 09:27:22编辑:auto阅读(2721)
1.通过Python获取Cookie,保存到本地
代码如下:
#!/usr/bin/python
import http.cookiejar, urllib.request
'''
获取Cookie保存到本地
'''
def get_baidu_cookies(url):
filename = 'E:\\baiducookies.txt';
cookie = http.cookiejar.LWPCookieJar(filename);
handler = urllib.request.HTTPCookieProcessor(cookie);
opener = urllib.request.build_opener(handler);
response = opener.open(url);
cookie.save(ignore_discard=True, ignore_expires=True);
if response.status == 200:
return 1;
return 0;
# 调用获取百度的cookie
res = get_baidu_cookies('https://www.baidu.com');
print(res);
代码截图:

运行截图:


上一篇: Debian服务器之安装Python3.
下一篇: Python基础-你必备的语言技能包
51754
51439
41848
38620
33112
30105
28775
23773
23686
22053
96°
2285°
2980°
2485°
2423°
3039°
2435°
3241°
5345°
5159°