Home  >  Article  >  Backend Development  >  Python crawler returns 403 error solution

Python crawler returns 403 error solution

伊谢尔伦
伊谢尔伦Original
2017-04-29 10:05:506441browse

Question

When crawling data, usually the debugging information is:

DEBUG: Crawled (200) <GET http://www.php.cn/> (referer: None)

If

DEBUG: Crawled (403) <GET http://www.php.cn/> (referer: None)

appears, it means that the website uses anti-web-crawling technique ( Used by Amazon), it is relatively simple to check the user agent (User Agent) information.

Solution

Construct a User Agent in the request header, as shown below:

def start_requests(self):  
    yield Request("http://www.php.cn/",  
                  headers={&#39;User-Agent&#39;: "your agent string"})


The above is the detailed content of Python crawler returns 403 error solution. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn