Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/139.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python2中通过scrapy从web读取json_Python_Json_Python 2.7_Web Scraping_Scrapy - Fatal编程技术网

在Python2中通过scrapy从web读取json

在Python2中通过scrapy从web读取json,python,json,python-2.7,web-scraping,scrapy,Python,Json,Python 2.7,Web Scraping,Scrapy,我想从网页中提取JSON数据,所以我检查了它。我需要的数据以以下格式存储: <script type="application/ld+json"> { 'data I want to extract' } </script> 但它不起作用,我该如何改变它 您需要在HTML源代码中找到该脚本元素,提取其文本,然后使用json.loads()加载: 在这里,我使用不太常见的应用程序/ld+json来定位脚本,但是还有许多其他选项,比如,使用

我想从网页中提取JSON数据,所以我检查了它。我需要的数据以以下格式存储:

<script type="application/ld+json">
    {
     'data I want to extract'
    }
    </script>

但它不起作用,我该如何改变它

您需要在HTML源代码中找到该
脚本
元素,提取其文本,然后使用
json.loads()加载:

在这里,我使用不太常见的
应用程序/ld+json
来定位
脚本
,但是还有许多其他选项,比如,使用脚本本身中的一些文本来定位脚本:

//script[contains(., 'Restaurant')]

您需要在HTML源代码中找到
script
元素,提取它的文本,然后使用
json.loads()加载它:

在这里,我使用不太常见的
应用程序/ld+json
来定位
脚本
,但是还有许多其他选项,比如,使用脚本本身中的一些文本来定位脚本:

//script[contains(., 'Restaurant')]
//script[contains(., 'Restaurant')]