【发布时间】:2019-11-18 18:01:55
【问题描述】:
我正在使用 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)
【问题讨论】:
-
你尝试过python的json模块吗?我想这对你会很有帮助。
-
我会尝试让你知道如果不起作用!谢谢你!
-
尝试阅读我的这个答案link 这将帮助您读取和写入数据到 json 文件
标签: web-scraping scrapy