尝试从网络获取链接

时间:2019-11-29 19:46:15

标签: python xpath hyperlink scrapy href

该代码仅获得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,
    }

1 个答案:

答案 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,}