scrapy shell 遇到的問題

有時候用scrapy shell來調試很方便,可是有些網站有防爬蟲機制,因此使用scrapy shell會返回403,好比下面html

  

有兩種解決方法:python

  (1):第一種方法是在命令上加上-s USER_AGENT='Mozilla/5.0'shell

  第一種方法最簡單可是每次操做都要加上去很繁瑣,第二種方法比較好。scrapy

  (2):第二種方法是修改scrapy的user-agent默認值網站

  找到python的:安裝目錄下的default_settings.py文件,好比個人C:\Users\0923\AppData\Local\Programs\Python\Python37\Lib\site-packages\scrapy\settings  調試

  把htm

    USER_AGENT = 'Scrapy/%s (+http://scrapy.org)' % import_module('scrapy').__version__blog

  改成it

    USER_AGENT = 'Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0'

io

  使用shell再次,發現已經能夠正常訪問html不會在出現403錯誤了。

  

相關文章
相關標籤/搜索