Skip to content
Advertisement

Extract data from Json: Error JSONDecodeError: Expecting value

import json
import requests
from bs4 import BeautifulSoup

url = 'https://play.google.com/store/apps/details?id=shooter.online.warplanes&hl=en'
data = requests.get(url)
soup = BeautifulSoup(data.text, 'html.parser')
script = soup.find('script', type='application/ld+json')
dt=json.loads(script.get_text())

Error : File “C:UsersAdminanaconda3libjsondecoder.py”, line 355, in raw_decode raise JSONDecodeError(“Expecting value”, s, err.value) from None JSONDecodeError: Expecting value

Advertisement

Answer

This is how you do it:

import json

import requests
from bs4 import BeautifulSoup

url = 'https://play.google.com/store/apps/details?id=shooter.online.warplanes&hl=en'
script = BeautifulSoup(requests.get(url).text, 'html.parser').find('script', type='application/ld+json')
print(json.loads(script.string)["name"])

Output:

Sky Combat: war planes online simulator PVP
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement