Scrapy Shell Debug Returns a 403 error

Source: Internet
Author: User



(1): The first method is to add-s user_agent= ' mozilla/5.0 ' on the command



(2): The second method is to modify the User-agent default value of Scrapy



Locate the Python: default_settings.py file under the installation directory,



C:\Program Files (x86) \anaconda2\envs\scrapy\lib\site-packages\scrapy\settings\default_settings.py



Modified 269 lines, user_agent;



User_agent = ' mozilla/5.0 (Windows NT 6.1; Win64; x64) applewebkit/537.36 (khtml, like Gecko) chrome/55.0.2883.87 safari/537.36 '






(2): section constructs a user Agent on the request header, as follows:


 
 
1 def start_requests(self):  
2     yield Request("http://www.baidu.com/",  
3                   headers={‘User-Agent‘: "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36"})  





Scrapy Shell Debug Returns a 403 error


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.