【问题标题】:I can't use the data I get from the web我无法使用从网络上获取的数据
【发布时间】:2021-11-18 23:11:04
【问题描述】:

我正在从网络获取数据,但我不能像 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"])

【问题讨论】:

    标签: python json dictionary beautifulsoup request


    【解决方案1】:

    您会收到 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'])
    

    【讨论】:

      猜你喜欢
      • 2013-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-02
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 2021-12-20
      相关资源
      最近更新 更多