天天看點

Python爬蟲:scrapy架構Spider類參數設定Spider設定settings.py或者custom_settings

Spider設定

參數 說明 示例
name 爬蟲名稱,必須唯一 name = “myspider”
handle_httpstatus_list 需要處理的狀态碼 handle_httpstatus_list = [404]
download_delay 下載下傳延時(機關:s秒) download_delay = 5
allowed_domains 域名限制 allowed_domains = [“baidu.com”]
custom_settings 使用者設定,單獨設定爬蟲參數 custom_settings ={‘RETRY_TIMES’: 3}
start_urls 起始連結設定 start_urls = [“ http://www.baidu.com “]

settings.py或者custom_settings

USER_AGENT 請求頭
ROBOTSTXT_OBEY = False 是否遵守robots協定
DOWNLOAD_DELAY = 2 同一個站點抓取延遲(秒s)
CONCURRENT_REQUESTS_PER_DOMAIN = 1 對同一個站點并發線程
CONCURRENT_REQUESTS_PER_IP = 1 對同一個ip并發線程