我正在从网络获取数据,但我不能像使用json或字典一样使用它。
import requests
from bs4 import BeautifulSoup
url = "http://www.omdbapi.com/?apikey=73a4d84d&t=Tenet"
response = requests.get(url)
content = response.content
soup = BeautifulSoup(content,"html.parser")
print(soup["Title"])
得到JSON响应。您可以使用方便的Response.json()
方法对其进行反序列化。
import requests
url = "http://www.omdbapi.com/?apikey=73a4d84d&t=Tenet"
response = requests.get(url)
data = response.json() # same as data = json.loads(response.text) after import json
print(data)
print(data['Title'])