import requests
import jsonpath
url='https://movie.douban.com/top250'
html=requests.get(url).text
print(html)
# f=open(html)
# html1=eval(html) #错误示范
html_json=html.jsons()['title']
# f=open(html_json)
title_json=jsonpath.jsonpath(html_json,'$..title')
print(title_json)
html_json=html.jsons()['title']
AttributeError: 'str' object has no attribute 'jsons'
看了很多解答,都是说load是返回文件对象,loads返回是str格式,所以无法解析。但是基础不扎实,没看出来有什么问题。欢迎解答
requests.get(url).text
返回的是html,不是json,所以不能用json解析。解析html可以用lxml或beautifulsoap.