The following is my code:
import numpy as np
import pandas as pd
import requests
from bs4 import BeautifulSoup
stats_page = requests.get('https://www.sports-reference.com/cbb/schools/loyola-il/2020.html')
content = stats_page.content
soup = BeautifulSoup(content, 'html.parser')
table = soup.find(name='table', attrs={'id':'per_poss'})
html_str = str(table)
df = pd.read_html(html_str)[0]
df.head()
And I get the error: ValueError: No tables found.
However, when I swap attrs={'id':'per_poss'}
with a different table id like attrs={'id':'per_game'}
I get an output.
I am not familiar with html and scraping but I noticed in the tables that work, this is the html: <table class="sortable stats_table now_sortable is_sorted" id="per_game" data-cols-to-freeze="2">
And in the tables that don't work, this is the html: <table class="sortable stats_table now_sortable sticky_table re2 le1" id="totals" data-cols-to-freeze="2">
It seems the table classes are different and I am not sure if that is causing this problem and how to fix it if so.
Thank you!