Home > Mobile >  I can't use the data I get from the web
I can't use the data I get from the web

Time:09-27

I'm getting data from the web but I can't use it like a json or dictionary.

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"])

CodePudding user response:

You get JSON response. You can use convenience Response.json() method to deserialize it.

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'])
  • Related