python 淘宝爬虫cookie问题

代码如下:

import requests
url = "https://s.taobao.com/search?q=墨点英语字帖衡水体女英文字帖中考英语满分作文英语词汇&imgfile=&ie=utf8&sort=default"
headers = {
                'pragma': 'no-cache',
                'cache-control': 'no-cache',
                'upgrade-insecure-requests': '1',
                'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
                'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
                'accept-encoding': 'gzip, deflate, br',
                'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
                'cookie': "thw=cn; t=b79929da96d98891a1226e8fdf038702; enc=LSBTPf%2FOY1TR90Odi%2FzvYRICnYO%2B4sEEEly7PJXJrRzIiIGyKoEBZ6Bl89AN8kGTCay3gMFwrAu4Nj3%2B9ySs0Q%3D%3D; cookie2=155ad3a9df0740548b42a27c8e44a2f2; _tb_token_=ebefb6e1aee55; x=2263306098; unb=2200742097976; sn=%E4%B8%89%E5%91%B3%E5%9B%BE%E4%B9%A6%E4%B8%93%E8%90%A5%E5%BA%97%3A%E9%B1%BC%E9%B1%BC; csg=a336467b; skt=f0c3eb08b1feae17; cna=EtuSFgujo0kCAbR755gh2gAi; v=0; uc1=cookie14=UoTbmhmpBl68IQ%3D%3D&lng=zh_CN; alitrackid=www.taobao.com; lastalitrackid=www.taobao.com; hng=CN%7Czh-CN%7CCNY%7C156; JSESSIONID=C7908A47A0481A4F6840705CCD940B6E; l=dBQhmWlPQgWw0sqsBOCMIbFNTb_tQIRfgu--bVg2i_5Nt681mM7OoX1FIFJ6cjWAGeLB4WtSLwvThFsgJIo4ne2e4AadZxkDB; isg=BPj4FOSO0lbtoz7UD0kYyj43yaaKYVzrjm3N8zJpUzPmTZk32nMCe0NvAQXYHRTD"
                }
response = requests.get(url, headers=headers)
print(response.text)

爬取天猫宝贝收付款信息,url时不时会重定向到登录页面,更换headers中cookie无法解决,使用同一局域网下不同电脑仍然无法解决

更换cookie方法:用不同天猫账号登录网页,然后在console中输入document.cookie获取cookie信息,更换headers中cookie

是更换cookie的方法有问题,还是其他什么原因?求大神告知!!!

查看全部
weixin_51221506
weixin_51221506
2020/12/02 23:54
  • python
  • 点赞
  • 收藏
  • 回答
    私信

1个回复