Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.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
Python 如果我需要从网页中提取json数据,那么该网页必须具有某种json类型的数据,或者我们可以从任何类型的网页中提取jason数据?_Python_Json - Fatal编程技术网

Python 如果我需要从网页中提取json数据,那么该网页必须具有某种json类型的数据,或者我们可以从任何类型的网页中提取jason数据?

Python 如果我需要从网页中提取json数据,那么该网页必须具有某种json类型的数据,或者我们可以从任何类型的网页中提取jason数据?,python,json,Python,Json,我写下面的代码是为了练习json文件,我无法从网页中提取json数据。请更正代码并帮助我,什么样的网页适合提取json文件,或者我们可以从任何类型的网页中提取json import urllib.request url="https://x-rates.com/table/?from=USD&amount=1" source_file=urllib.request.urlopen(url) page=source_file.read() data=json.loads(page

我写下面的代码是为了练习json文件,我无法从网页中提取json数据。请更正代码并帮助我,什么样的网页适合提取json文件,或者我们可以从任何类型的网页中提取json

 import urllib.request
 url="https://x-rates.com/table/?from=USD&amount=1"
 source_file=urllib.request.urlopen(url)
 page=source_file.read()
 data=json.loads(page)
 print(data)

大多数web API都以json格式返回数据。
如果您试图抓取网站,则必须使用任何解析器解析html或xml。

是的,当然页面必须返回有效的JSON字符串,才能将其解码为JSON。