# -*- coding: utf-8 -*- # Scrapy settings for chouti project # # For simplicity, this file contains only settings considered important or # commonly used. You can find more settings consulting the documentation: # # https://doc.scrapy.org/en/latest/topics/settings.html # https://doc.scrapy.org/en/latest/topics/downloader-middleware.html # https://doc.scrapy.org/en/latest/topics/spider-middleware.html BOT_NAME = 'chouti' # 爬虫的名字 SPIDER_MODULES = ['chouti.spiders'] NEWSPIDER_MODULE = 'chouti.spiders' # Crawl responsibly by identifying yourself (and your website) on the user-agent # user-agent表示请求头,可以根据请求头对爬虫进行屏蔽,也可以更改请求头,模拟浏览器 USER_AGENT = 'chouti (+http://www.yourdomain.com)' # Obey robots.txt rules ROBOTSTXT_OBEY = True # 是否遵守robot协议,一般网站都会写一些规定,哪些数据可以爬,哪些不可以爬 # Configure maximum concurrent requests performed by Scrapy (default: 16) CONCURRENT_REQUESTS = 32 # 并发请求数,这里表示一次发出32个爬虫。并发数越大,每次获取的信息也越多。如果太大,网站可能就会封掉我们的ip # Configure a delay for requests for the same website (default: 0) # See https://doc.scrapy.org/en/latest/topics/settings.html#download-delay # See also autothrottle settings and docs DOWNLOAD_DELAY = 3 # 延迟,表示没延迟三秒请求一次,如果访问过快,有可能会被反 # The download delay setting will honor only one of: CONCURRENT_REQUESTS_PER_DOMAIN = 16 # 针对每个域名进行16个并发,比方说我域名写了A站和B站,相当于放出了32个虫子 CONCURRENT_REQUESTS_PER_IP = 16 # 每一个ip进行16个并发。大公司不可能只有一个服务器,而是有很多台,然后对外只有一个域名。当我们访问的时候,进行负载均衡,把请求分配在不同的服务器上。 # Disable cookies (enabled by default) COOKIES_ENABLED = False # 是否获取cookie,获取的response是否解析cookie # Disable Telnet Console (enabled by default) TELNETCONSOLE_ENABLED = False # 可以暂停查看状态 # Override the default request headers: DEFAULT_REQUEST_HEADERS = { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'en', } # 默认的请求头,当然在Request中还可以单独传 # Enable or disable spider middlewares # See https://doc.scrapy.org/en/latest/topics/spider-middleware.html # SPIDER_MIDDLEWARES = { # 'chouti.middlewares.ChoutiSpiderMiddleware': 543, # } # Enable or disable downloader middlewares # See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html # DOWNLOADER_MIDDLEWARES = { # 'chouti.middlewares.ChoutiDownloaderMiddleware': 543, # } # Enable or disable extensions # See https://doc.scrapy.org/en/latest/topics/extensions.html EXTENSIONS = { #'scrapy.extensions.telnet.TelnetConsole': None, 'chouti.extensions.MyExtend': 300 } # Configure item pipelines # See https://doc.scrapy.org/en/latest/topics/item-pipeline.html # ITEM_PIPELINES = { # 'chouti.pipelines.ChoutiPipeline': 300, # } # Enable and configure the AutoThrottle extension (disabled by default) # See https://doc.scrapy.org/en/latest/topics/autothrottle.html # AUTOTHROTTLE_ENABLED = True # The initial download delay # AUTOTHROTTLE_START_DELAY = 5 # The maximum download delay to be set in case of high latencies # AUTOTHROTTLE_MAX_DELAY = 60 # The average number of requests Scrapy should be sending in parallel to # each remote server # AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0 # Enable showing throttling stats for every response received: # AUTOTHROTTLE_DEBUG = False ''' 上面一坨是用来做智能限速的 ''' # Enable and configure HTTP caching (disabled by default) # See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings # HTTPCACHE_ENABLED = True # HTTPCACHE_EXPIRATION_SECS = 0 # HTTPCACHE_DIR = 'httpcache' # HTTPCACHE_IGNORE_HTTP_CODES = [] # HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage' DEPTH_LIMIT = 0 DEPTH_PRIORITY = 0 # 广度优先还是深度优先,只能是0或者1。0是深度优先,1是广度优先 # 当然在配置文件里,必须指定一下,过滤所用到的类 # 这样才会用我们定义的类进行过滤 #DUPEFILTER_CLASS = 'chouti.duplication.DupeFilter'