Issue
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"}]'
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)
Answered By - bugless-soup
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.