我创建了一个非常缓慢的新Scrapy蜘蛛。它每秒只能抓取两页,而我创建的其他Scrapy抓取工具的抓取速度更快。缓慢的Scrapy刮刀的原因
我想知道它是什么可能导致此问题,以及如何解决这个问题。代码与其他蜘蛛并没有太大区别,我不确定它是否与问题有关,但如果您认为它可能涉及到,我会添加它。
事实上,我的印象是请求不是异步的。我从来没有遇到过这样的问题,我对Scrapy相当陌生。
编辑
这里的蜘蛛:
class DatamineSpider(scrapy.Spider):
name = "Datamine"
allowed_domains = ["domain.com"]
start_urls = (
'http://www.example.com/en/search/results/smth/smth/r101/m2108m',
)
def parse(self, response):
for href in response.css('.searchListing_details .search_listing_title .searchListing_title a::attr("href")'):
url = response.urljoin(href.extract())
yield scrapy.Request(url, callback=self.parse_stuff)
next_page = response.css('.pagination .next a::attr("href")')
next_url = response.urljoin(next_page.extract()[0])
yield scrapy.Request(next_url, callback=self.parse)
def parse_stuff(self, response):
item = Item()
item['value'] = float(response.xpath('//*[text()="Price" and not(@class)]/../../div[2]/span/text()').extract()[0].split(' ')[1].replace(',',''))
item['size'] = float(response.xpath('//*[text()="Area" and not(@class)]/../../div[2]/text()').extract()[0].split(' ')[0].replace(',', '.'))
try:
item['yep'] = float(response.xpath('//*[text()="yep" and not(@class)]/../../div[2]/text()').extract()[0])
except IndexError:
print "NO YEP"
else:
yield item
有很多事情可能会导致这种情况。你能提供蜘蛛源和抓取日志吗?如果您正在运行unix系统,则可以执行scrapy crawl spider 2&1 spider.log',然后在此处发布该日志。 – Granitosaurus
我加了蜘蛛,我会尽快添加日志,(我现在正在运行它)。当我看日志时,速度在45到80页/分钟之间。 ;( – AimiHat
你可以尝试发现是代码是慢速分析代码,像https://github.com/rkern/line_profiler – Ceppo93