I'm trying to extract tables from this webpage, but am only able to get the pitching table for example. I want to get the hitting table as well, which would in theory be this URL: https://www.covers.com/sport/baseball/mlb/matchup/279605#hitting
But that doesn't get me any different result. Separately I want to be able to extract things like the Last 5 and Last 10 options, but I assume the answer is going to be same for all of these. How would I go about setting this up so it could dynamically select and extract these tables?
import pandas as pd
import requests
from bs4 import BeautifulSoup
url = 'https://www.covers.com/sport/baseball/mlb/matchup/279605'
pd.set_option('display.max_rows', 5000)
pd.set_option('display.max_columns', 5000)
pd.set_option('display.width', 1500)
html = requests.get(url).content
df_list = pd.read_html(html)
df = df_list[12]
print(df)
The hitting table is loaded from different URL. You can use this example to load it:
Prints: