1. 程式人生 > >Python爬蟲:scrapy框架Spider類引數設定

Python爬蟲:scrapy框架Spider類引數設定

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 起始連結設定

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併發執行緒