该代码仅获得1个URL列表,然后停止。它应该获得209项。为什么只打印一行?
def parse_link(self, response):
# Extract the list of products
results = response.xpath('//li[@class="s-item "]')
# Extract info for each product
for product in results:
name = product.xpath('//*[@class="s-item__link"]').extract_first()[30:124]
yield{
"Name":name,
}
答案 0 :(得分:0)
缩进不正确(您需要在yield
循环内移动for
)
def parse_link(self, response):
# Extract the list of products
results = response.xpath('//li[@class="s-item "]')
# Extract info for each product
for product in results:
name = product.xpath('//*[@class="s-item__link"]').extract_first()[30:124]
yield {"Name":name,}