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)