http://www.tianyancha.com/sea…
想要获取图片里的cookie的所有值
1
2
3
4
5
6
7
8
9
10#coding=utf-8
import requests
session=requests.session()
url='http://www.tianyancha.com/search/%E7%99%BE%E5%BA%A6?checkFrom=searchBox'
headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0'}
html=session.get(url=url,headers=headers)
cookies_dict=html.cookies.get_dict()
print html.cookies
print cookies_dict
print html.headers['set-cookie']
输出的值分别是
//, ]>
//{‘tnet’: ‘180.102.115.248’, ‘TYCID’: ’20a503a2ba6c4f7da54cef8f5c374b57′}
//TYCID=20a503a2ba6c4f7da54cef8f5c374b57; Domain=.tianyancha.com; Expires=Thu, 11-Aug-2016 12:38:30 GMT; Path=/, tnet=180.102.115.248; Domain=.tianyancha.com; Expires=Thu, 11-Aug-2016 12:38:30 GMT; Path=/
并不完整,怎么才能获取完整的cookie值呢?
_pk_id和_pk_ses好像是js自己设置的,其他cookies有些是从js发起的别的请求返回的。要想获取全部cookies,必须模拟载入页面,phantomjs可以实现这个功能。
把输出的值去掉那些乱七八遭的,比如