简体   繁体   English

Spider用于在Scrapy中解析JSON

[英]Spider for parsing JSON in scrapy

I have been using scrapy for some time now and I wish to know what is the best way to parse JSON. 我已经使用scrapy一段时间了,我想知道解析JSON的最佳方法是什么。 There are specially designed spiders for XML and CSV in scrapy viz. 在scrapy viz中,有专门为XML和CSV设计的蜘蛛。 XMLFeedSpider and CSVFeedSpider . XMLFeedSpiderCSVFeedSpider Is there any such spider for JSON too ? JSON是否也有这种蜘蛛?

There is no default JSON parser for Scrapy, but you can use the json module to parse your response and convert it to items: Scrapy没有默认的JSON解析器,但是您可以使用json模块来解析您的响应并将其转换为项目:

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

However if you plan to write a general solution like CSVFeedSpider feel free to contribute it to the Scrapy project but I guess json.loads does the trick of consuming JSON responses. 但是,如果您打算编写像CSVFeedSpider这样的通用解决方案, CSVFeedSpider随时将其贡献给Scrapy项目,但我想json.loads确实可以使用JSON响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM