【发布时间】:2020-02-13 10:26:34
【问题描述】:
这是我第一次在 python 中使用 Scrapy 框架。
所以我编写了这段代码。
# -*- coding: utf-8 -*-
import scrapy
class SpiderSpider(scrapy.Spider):
name = 'spider'
start_urls = [
'https://www.emag.ro/televizoare/c'
]
def parse(self, response):
for i in response.xpath('//div[@class="card-section-wrapper js-section-wrapper"]'):
yield {
'product-name': i.xpath('.//a[@class="product-title js-product-url"]/text()')
.extract_first().replace('\n','')
}
next_page_url = response.xpath('//a[@class="js-change-page"]/@href').extract_first()
if next_page_url is not None:
yield scrapy.Request(response.urljoin(next_page_url))
当我查看该网站时,它有超过 800 种产品。但我的脚本只占用了前 2 页近 200 种产品...
我尝试使用 css 选择器和 xpath,都是相同的错误。
谁能找出问题出在哪里?
谢谢!
【问题讨论】:
标签: python scrapy frameworks