码迷,mamicode.com
首页 > 其他好文 > 详细

在Scrapy里设置Cookies 要注意一点!

时间:2019-04-17 16:39:01      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:ack   一点   info   control   secure   code   cin   keep   enc   

1.requests里设置cookies,可以将cookies放入headers里一同提交。

 

{Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,
 Accept-Encoding: gzip, deflate,
 Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,
 Cache-Control: max-age=0,
 Connection: keep-alive,
 Cookie: __cfduid=d50cf692a2f654986d51b98e6c1bad6c41535939301; session=.eJwlzj0OwjAMQOG7eO6Q2Emc9DKV6x-oEB1amBB3pxLS27_3gSUOP-8wv463T7BsBjMEiaIRMZe-MgfXKozmShqWXZVMOqdW-jDElkbm2r2IKqt0WYkwczKLNjyKmqUW2Nekgv3KMg2mWp1TRcm54ShNROvl5FARmOB9-vGfeWz7bZenw_cHGzsyUA.Dw5FeA.xD0ofpGXJUvDLYeCrMn08E24HKM,
 DNT: 1,
 Host: exercise.kingname.info,
 Upgrade-Insecure-Requests: 1,
 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36}

 

 

 

2.但是,如果使用Scrapy的时候需要Cookies,就不能把Cookies放在Headers里面。在Scrapy发起请求的时候,有一个单独的参数来设置Cookies:

yield scrapy.Request(url,
                     callback=self.xxx,
                     headers=headers,
                     cookies={__cfduid: d50cf692a2f654986d51b98e6c1bad6c41535939301,
                              session: .eJwlzj0OwjAMQOG7eO6Q2Emc9DKV6x-oEB1amBB3pxLS27_3gSUOP-8wv463T7BsBjMEiaIRMZe-MgfXKozmShqWXZVMOqdW-jDElkbm2r2IKqt0WYkwczKLNjyKmqUW2Nekgv3KMg2mWp1TRcm54ShNROvl5FARmOB9-vGfeWz7bZenw_cHGzsyUA.Dw5FeA.xD0ofpGXJUvDLYeCrMn08E24HKM})

 

在Scrapy里设置Cookies 要注意一点!

标签:ack   一点   info   control   secure   code   cin   keep   enc   

原文地址:https://www.cnblogs.com/longsongpong/p/10724311.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!