我正在尝试将数据从网站加载到json文件中
when i try this code, nothing is wrong:
import requests
import json
url="https://leoclub-ssmc.blogspot.com/?m=1"
r=requests.get(url)
print(r.text)
this code above show the web's full page with html code without error.
but when i try to load all the code into a json file then it shows some error message
import requests
import json
url="https://leoclub-ssmc.blogspot.com/?m=1"
r=requests.get(url)
print(r.json)
上述代码显示: 响应[200]的绑定方法Response.json [程序完成]
moving on::
import requests
import json
url="https://leoclub-ssmc.blogspot.com/?m=1"
r=requests.get(url).json()
print(r)
★★现在显示此错误消息:“raise JSONDecodeError(“预期值”,s,err.value)从None开始 json.decoder.JSONDecodeError:应为值:第1行第1列(字符0)” [程序完成]
我只想在json文件中加载数据,然后在我的应用程序中具体显示它们
您使用的第三种方法是正确的:
然而,这个页面实际上并没有返回JSON,因此
JSONDecodeError
如果您希望抓取页面,并将数据放入Python数据结构或JSON中,您可能应该研究用于web抓取的
BeautifulSoup4
或Selenium
之类的库您试图阅读的网站不包含JSON数据。 请尝试此网站:url=”http://api.plos.org/search?q=title:DNA"
如果您试图解析HTML文件,请检查BeautifulsoupAPI
相关问题 更多 >
编程相关推荐