Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Extracting data from a dictionary in bs4?

My code:

import requests
from bs4 import BeautifulSoup

name = input("Player's name: ")
url = f'https://www.futwiz.com/en/searches/career22/{name}'

r = requests.get(url)
print(r.content)

soup = BeautifulSoup(r.text,'html.parser')
results = soup.find(attrs={"lineid"})
print(results)

I can’t get the data from the dictionary.
r.text looks like this:

b'[{"lineid":"438","cardname":" Hakimi","name":"Achraf
Hakimi","urlname":"achraf-hakimi","rating":"85","potential":"89","club":"73","pid":"235212","position":"RB","nation":"129","league":"16","acceleration":"93","agility":"84","balance":"79","jumping":"80","reactions":"84","sprintspeed":"95","stamina":"93","strength":"74","aggression":"75","positioning":"79","tactaware":"78","vision":"78","ballcontrol":"83","crossing":"86","curve":"77","dribbling":"81","finishing":"75","fkacc":"74","headingacc":"68","longpass":"73","longshot":"73","marking":"75","penalties":"60","shortpass":"81","shotpower":"80","slidetackle":"76","standingtackle":"78","volleys":"74","fname":"Achraf","lname":"Hakimi","dob":"22","height":"181","foot":"Right","traits":null,"teamname":"Paris
Saint-Germain","leaguename":"France Ligue 1
(1)","nationname":"Morocco","skillmoves":"3","weakfoot":"4"}]’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’m trying to access "lineid" and get "438"

>Solution :

BeautifulSoup is a HTML parser, the response you’re receiving is a JSON.

This script could help you:

import json
import requests

name = input("Player's name: ")
url = f'https://www.futwiz.com/en/searches/career22/{name}'

r = requests.get(url)
results = [line["lineid"] for line in json.loads(r.text)]
print(results)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading