python如何获得cookies全部内容
天蓬老师
天蓬老师 2017-04-17 15:50:46
0
3
1101

如图

图片上是浏览器抓包的cookies结果,cookies有3个内容,分别是Hm_lpvt,Hm_lvt,__c_Fw7.
我求教的问题,python怎么得到这样的cookies?
我的做法:分别用了requests.session(),urllib2,pycurl三种方法, 却都是只获得了__c_Fw7,另外2个怎么得到呢?
补充:Hm_lpvt的values只保存在浏览器会话,它的值浏览器刷新一次就更改一次。
pycurl库得到cookies的截图,__c_18j9,就是上面说的__c_Fw7。

response截图,看不到 set-cookies,或许是我方法不对,才看不到?

百度response的确是有set-cookie

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(3)
小葫芦

You can write your own code to control cookies, mainly by looking at the set-cookie field in the headers of reqsponse, then parsing it out, and then passing it to the headers of the next request.
For example, the following is the set-cookie field in the response when I request www.baidu.com

'BAIDUID=A611EF4EDE31F245A2F0520055218EE2:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com, BIDUPSID=A611EF4EDE31F245A2F0520055218EE2; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com, PSTM=1441330839; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com, BDSVRTM=0; path=/, BD_HOME=0; path=/, H_PS_PSSID=16415_1455_17156_13245_12824_12867_17105_14951_17000_16935_17004_17072_15592_12247_13932_16969_17051; path=/; domain=.baidu.com'

Just parse it yourself and then pass it to the request.

黄舟

The browser will parse the html and then access the css, images, javascript and other resources in the requested page, and then run the js script, and there will be various other requests.

The script I wrote will only request once and will not parse html.

If the developer hides a cookie in the request of the js script, your script will be missing cookies.

You can use Chrome's developer tools to track all requests for page loading, see which request the set-cookies directive is in, and then use a script to simulate it.

刘奇

Refer to the code I am writing to log in to Jirouter http://www.cnblogs.com/gayhub/p/5476712.html

The correct Content-Type must be specified, otherwise COOKIES cannot be obtained.
It is better to use fiddler as a packet capture tool.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!