通过Python读取本地Cookie,加载指定页面

1.通过Python读取本地Cookie,加载指定页面

创新互联建站自2013年创立以来,先为郁南等服务建站,郁南等地企业,进行企业商务咨询服务。为郁南企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

代码如下:

#!/usr/bin/python

import http.cookiejar, urllib.request

'''

加载cookies进行请求

'''

def get_baidu_page(url):

cookie = http.cookiejar.LWPCookieJar()

cookie.load('E:\\baiducookies.txt', ignore_discard=True, ignore_expires=True)

handler = urllib.request.HTTPCookieProcessor(cookie)

opener = urllib.request.build_opener(handler)

response = opener.open(url)

return response;

response = get_baidu_page('https://www.baidu.com');

if response.status == 200:

print(response.headers);

代码截图:

通过Python读取本地Cookie,加载指定页面

运行截图:

通过Python读取本地Cookie,加载指定页面

通过Python读取本地Cookie,加载指定页面


本文题目:通过Python读取本地Cookie,加载指定页面
转载来于:http://myzitong.com/article/ppjceo.html