scrapy忽略我的settins.py
我的scraper.py
import scrapy
class BlogSpider(scrapy.Spider):
name = 'blogspider'
start_urls = ['https://www.doctolib.de/directory/a']
def parse(self, response):
if not response.xpath('//title'):
yield Request(url=response.url, dont_filter=True)
if not response.xpath('//lead'):
yield Request(url=response.url, dont_filter=True)
for title in response.css('.seo-directory-doctor-link'):
yield {'title': title.css('a ::attr(href)').extract_first()}
next_page = response.css('li.seo-directory-page > a[rel=next] ::attr(href)').extract_first()
if next_page:
yield scrapy.Request(response.urljoin(next_page), callback=self.parse)
在放置脚本的同一文件夹中是一个settings.py,其中包含以下内容
# Retry many times since proxies often fail
RETRY_TIMES = 5
# Retry on most error codes since proxies fail for different reasons
RETRY_HTTP_CODES = [500, 503, 504, 400, 403, 404, 408]
DOWNLOADER_MIDDLEWARES = {
'scrapy.downloadermiddlewares.retry.RetryMiddleware': 90,
# Fix path to this module
'botcrawler.randomproxy.RandomProxy': 600,
'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware': 110,
}
PROXY_LIST = '/home/user/botcrawler/botcrawler/proxy/list.txt'
为什么他不加载这个文件?我做错了什么?
由于
答案 0 :(得分:0)
settings.py文件应该与spiders文件夹并行,你的scraper.py应该在spiders文件夹中。您可以覆盖现有的settings.py文件。
答案 1 :(得分:0)
根据您最近的其他帖子判断,您似乎正在努力开始一个scrapy项目。阅读Scrapy教程here
是个好主意总之,它将描述如何使用命令scrapy startproject Blogspider
这将设置3个链接文件夹:Blogspider>> Blogspider>>蜘蛛
在第二个文件夹中将是items.py
和settings.py
文件以及其他几个文件。您只需要编辑items.py
文件。
在Spiders文件夹中放置蜘蛛,它将从之前的文件夹中读取items.py
和settings.py
文件等。