I’m trying to get the wins from the ‘Overall match stats’ on this page: https://www.fctables.com/teams/sunderland-194998/?template_id=11. Everything I try it just returns ‘None’. This isn’t the only page I have tried to use but every one seems to return ‘None’. I’m not very advanced in this so any help would be appreciated.
from bs4 import BeautifulSoup
import requests
URL = "https://www.fctables.com/teams/sunderland-194998/"
response = requests.get(URL)
soup = BeautifulSoup(response.text, "html.parser")
wins = soup.find('div', class_='text-success ')
print(wins)
I need it to output the ‘6’ which is the number of wins. Preferably as an integer.
2
Answers
BeautifulSoup famously is the package that lets
you parse other people’s HTML garbage as if it were grammatically correct.
The HTML grammar is, alas, a bit complicated.
You got hung up on the trailing SPACE in the class name.
Just strip it.
Steve Harvey wants to know, "Could SPACE ever be
part of a valid class name?"
Survey says
"nope!", the SPACE character is specifically prohibited.
You can change how you select the tags:
Prints:
The
stats
is a dictionary that contains: