其他分享
首页 > 其他分享> > urllib处理cookie

urllib处理cookie

作者:互联网

import http.cookiejar,urllib.request
# cookie=http.cookiejar.CookieJar()
# handle=urllib.request.HTTPCookieProcessor(cookie)
# opener=urllib.request.build_opener(handle)
# respose=opener.open('http://www.baidu.com')
# for item in cookie:
#     print(item.name+"="+item.value)

filename='cookies.txt'
cookie=http.cookiejar.MozillaCookieJar(filename)
handle=urllib.request.HTTPCookieProcessor(cookie)
opener=urllib.request.build_opener(handle)
respose=opener.open('http://www.baidu.com')
cookie.save(ignore_discard=True,ignore_expires=True)

 

标签:http,处理,request,urllib,opener,cookie,handle
来源: https://blog.csdn.net/m0_57006708/article/details/120117562