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

Web scraping 我想使用此查询或代码获取data.json中的数据,web-scraping,scrapy,Web Scraping,Scrapy,我使用VS-code+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(sel

我使用VS-code+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)

URL
https://app.cartinsight.io/sellers/all/amazon/
您要刮取的内容正在重定向到此URL
https://app.cartinsight.io/
。第二个URL不包含此XPath
“//td[@title='Show Contact']”
,这会导致跳过
parse
方法中的
for
循环,因此无法获得所需的结果

您是否尝试过python中的json模块?我想这会对你很有帮助。如果不起作用,我会尽量让你知道的!谢谢你,伙计!试着阅读我的答案,这将帮助你读写json文件中的数据