I was trying to gather some data for a data analysis project concerning italian football. Unfortunately I can't extract one specific table from the web page, even though the id is correct.
The code is the following one:
import requests
import pandas as pd
from bs4 import BeautifulSoup
url = "https://fbref.com/it/comp/11/gca/Statistiche-di-Serie-A#all_stats_gca"
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
table = soup.find('table', {'id': 'stats_gca'})
df = pd.read_html(str(table))[0]
print(df)
With this id ('stats_squads_gca_for') I have no problem, but with ('stats_gca') in my example I get no table as output and also the compiler says that there is no such table.
What am I doing wrong?
I've also tried by not using pandas but the result is the same. I expect to have missed something.
read_html(url)?JavaScriptto generate table - butBeautifulSoupcan't runJavaScript. And server may also send differentHTMLfor different browser (and different HTML when browser can't runJavaScript) so first check what you really have inresponse.content