如图
图片上是浏览器抓包的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
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
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.