Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.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 Can';t将html转换为JSON_Python_Json_Automation_Python Requests - Fatal编程技术网

Python Can';t将html转换为JSON

Python Can';t将html转换为JSON,python,json,automation,python-requests,Python,Json,Automation,Python Requests,我得到的错误是: AttributeError:'str'has object没有属性'json' 这行是什么weatherData=response.json(response)? 我想这会有用的 import json,requests,sys,os url='https://www.timeanddate.com' response=requests.get(url).text data=json.loads(response.text) weatherData=response.jso

我得到的错误是:

AttributeError:'str'has object没有属性'json'

这行是什么
weatherData=response.json(response)

我想这会有用的

import json,requests,sys,os

url='https://www.timeanddate.com'
response=requests.get(url).text
data=json.loads(response.text)
weatherData=response.json(response)
现在,
weatherData
是一本python字典

  • 如果问题中的URL是实际的URL,并且您实际上正在尝试将响应中的所有HTML转换为JSON,那么这是不可能的。HTML和JSON是不可转换的格式。您必须找到一个将返回实际JSON数据的API URL。也许你想结账

  • 如果问题中的URL是一个伪URL,并且您使用的是返回JSON响应的实际URL,那么请参阅此处的请求文档,了解如何从响应中获取JSON


  • 嗯,
    响应
    已经是文本(第4行)。然后您再次调用
    response.text
    import json
    response=requests.get(url)
    weatherData=json.loads(response.text)