用于在 scrapy 中解析 JSON 的蜘蛛

Spider for parsing JSON in scrapy

我使用 scrapy 已经有一段时间了,我想知道什么是最好的解析方法 JSON。在 scrapy 即中,有专门为 XML 和 CSV 设计的蜘蛛。 XMLFeedSpiderCSVFeedSpider。 JSON 也有这样的蜘蛛吗?

Scrapy 没有默认的 JSON 解析器,但您可以使用 json 模块来解析您的响应并将其转换为项目:

jsonresponse = json.loads(response.body_as_unicode())

但是,如果您打算编写像 CSVFeedSpider 这样的通用解决方案,请随时将其贡献给 Scrapy 项目,但我想 json.loads 会消耗 JSON 响应。