(博彩导航网) 用requests进行爬虫,怎么获得有cookie的字典?
在线博彩导航
在线博彩导航
当前位置 : 在线博彩导航 > 博彩导航网

(博彩导航网) 用requests进行爬虫,怎么获得有cookie的字典?

比如:f12观察到
Cookie:JSESSIONID=qzGdVaHzBrI1cg+9X2iPaCPS.undefined

session=requests.session
html1=session.geturl=url,headers=headers
html2=session.geturl=urlIndex,headers=headers,cookies=cookies????

怎么才能获取到这个字典呢{Cookie:JSESSIONID=qzGdVaHzBrI1cg+9X2iPaCPS.undefined}?
我输出html.cookies.values/items/get/get_dict,得到的结果都是:

<bound method RequestsCookieJar.keys of <RequestsCookieJar[Cookieversion=0, name=JSESSIONID, value=KEUJT8xlQFKX+r6R-fq1lhnI.undefined, port=None, port_specified=False, domain=218.57.139.24, domain_specified=False, domain_initial_dot=False, path=/, path_specified=True, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={}, rfc2109=False]>>

这样的类型能怎么转化呢?还是cookies直接赋值,另cookies=html1.cookies就行了?

requests的session就自动给你更新了cookies啊,何必再去获取,实在不放心,你可以抓包看看

http://stackoverflow.com/ques...
From the documentation:

get cookie from response

url = http://example.com/some/cooki...
r = requests.geturl
r.cookies

{example_cookie_name: example_cookie_value}

give cookie back to server on subsequent request

url = http://httpbin.org/cookies

cookies =dictcookies_are=working
r =requests.geturl,cookies=cookies

栏目列表

广告位

在线博彩导航