I'm attempting to scrape the table data from the following website: https://fantasyfootball.telegraph.co.uk/premier-league/statscentre/
The objective is to get all the player data and store it in a dictionary.
I'm using BeautifulSoup and I'm able to locate the table from the html content, however the table body that is returned is empty.
From reading other posts I saw this maybe be related to the way the website is slow to load the table data after loading the website, but I could not find a way around the problem.
My code is as follows:
from bs4 import BeautifulSoup
import requests
# Make a GET request to feth the raw HTML content
html_content = requests.get(url).text
# Parse the html content
soup = BeautifulSoup(html_content, "lxml")
# Find the Title Data within the website
player_table = soup.find("table", attrs={"class": "player-profile-content"})
print(player_table)
The result I get is this:
<table class="playerrow playlist" id="table-players">
<thead>
<tr class="table-head"></tr>
</thead>
<tbody></tbody>
</table>
The actual HTML code on the website is quite long as they pack a lot of data into each <tr>
as well as the subsequent <td>
so I won't post it here unless someone asks.
Suffice to say that there are several <td>
lines within the header row, as well as seval <tr>
lines within the body.