首頁  >  文章  >  後端開發  >  Python 爬蟲回傳403錯誤解決方法

Python 爬蟲回傳403錯誤解決方法

伊谢尔伦
伊谢尔伦原創
2017-04-29 10:05:506405瀏覽

問題

抓取資料時,通常調試資訊是:

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

如果出現

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

表示網站採用了防爬技術anti-web-crawling technique( Amazon所用),比較簡單即會檢查使用者代理程式(User Agent)資訊。

解決方法

在請求頭部建構一個User Agent,如下所示:

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


以上是Python 爬蟲回傳403錯誤解決方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn