我正在编写一个 Scrapy CrawlSpider,它读取第一页上的广告列表,获取一些信息,例如列表和广告 URL 的缩略图,然后向每个广告 URL 发出请求以获取其详细信息。
它在测试环境中工作和分页显然很好,但是今天尝试完整运行我在日志中意识到:
爬取 3852页(228 页/分钟),抓取256条(15 条/分钟)
我不明白 Crawled pages 和 Scraped items 之间存在如此大差异的原因。任何人都可以帮助我意识到这些物品在哪里丢失了?
我的蜘蛛代码:
class MySpider(CrawlSpider):
name = "myspider"
allowed_domains = ["myspider.com", "myspider.co"]
start_urls = [
"http://www.myspider.com/offers/myCity/typeOfAd/?search=fast",
]
#Pagination
rules = (
Rule (
SgmlLinkExtractor()
, callback='parse_start_url', follow= True),
)
#1st page
def parse_start_url(self, response):
hxs = HtmlXPathSelector(response)
next_page = hxs.select("//a[@class='pagNext']/@href").extract()
offers = hxs.select("//div[@class='hlist']")
for offer in offers:
myItem = myItem()
myItem['url'] = offer.select('.//span[@class="location"]/a/@href').extract()[0]
myItem['thumb'] = oferta.select('.//div[@class="itemFoto"]/div/a/img/@src').extract()[0]
request = Request(myItem['url'], callback = self.second_page)
request.meta['myItem'] = myItem
yield request
if next_page:
yield Request(next_page[0], callback=self.parse_start_url)
def second_page(self,response):
myItem = response.meta['myItem']
loader = myItemLoader(item=myItem, response=response)
loader.add_xpath('address', '//span[@itemprop="streetAddress"]/text()')
return loader.load_item()