我想使用此查询或代码获取data.json中的数据

我正在使用VS代码+ git bash将这些数据抓取到JSON中。但是我没有将任何数据转换成JSON或没有任何数据转换成JSON。 JSON文件为空。

import scrapy

class Contactsspider(scrapy.Spider):
    name= 'contacts'

    start_urls = [
        'https://app.cartinsight.io/sellers/all/amazon/'
    ]

    def parse(self,response):
        for contacts in response.xpath("//td[@title= 'Show Contact']"):
            yield{
                'show_contacts_td': contacts.xpath(".//td[@id='show_contacts_td']").extract_first()
                }
            next_page= response.xpath("//li[@class = 'stores-desc hidden-xs']").extract_first()
            if next_page is not None:
                next_page_link= response.urljoin(next_page)
                yield scrapy.Request(url=next_page_link,callback=self.parse)
charmprefect 回答:我想使用此查询或代码获取data.json中的数据

您要抓取的URL https://app.cartinsight.io/sellers/all/amazon/重定向到该URL https://app.cartinsight.io/。第二个URL不包含此XPath "//td[@title= 'Show Contact']",这会导致跳过for方法中的parse循环,因此您没有得到想要的结果。

本文链接:https://www.f2er.com/3083393.html

大家都在问