我第一次尝试使用api,并且我需要使用被调用的数据。当我运行我的脚本时,我得到了一个<Response [200]>
,所以我的代码是成功的,但是我如何查看和使用被调用的信息呢?谢谢!
发布于 2021-10-13 19:03:50
如果这是您请求api的方式,
r = requests.get("api")
通过这种方式,您将得到一个纯文本响应。
print(r.text)
您还可以通过这样做来获得json输出。
print(r.json())
发布于 2021-10-13 19:03:54
如果您使用的是requests
。
response = requests.get("some url")
response.status_code # get the status code
json_response = response.json() # convert response to json
print(json_response) # you can see dictionary-like structure
print(json_response["arbitrary"]) # you can access data just like normal dictionary
https://stackoverflow.com/questions/69564568
复制相似问题