我創建了一個非常緩慢的新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