Код: Выделить всё
import requests
from bs4 import BeautifulSoup
standings_url = "https://www.pro-football-reference.com/years/2023/index.htm"
data = requests.get(standings_url)
soup = BeautifulSoup(data.text)
standings_table1 = soup.select('table.stats_table')[0]
standings_table2 = soup.select('table.stats_table')[1]
links1 = standings_table1.find_all('a')
links2 = standings_table2.find_all('a')
all_links = [l.get('href') for l in links1] + [l.get('href') for l in links2]
team_links = [l for l in all_links if '/teams/' in l]
base_url = "https://www.pro-football-reference.com"
full_team_links = [base_url + l for l in all_links]
full_team_links
team_url = full_team_links[0]
data = requests.get(team_url)
data.text
import pandas as pd
games = pd.read_html(data.text, match="Schedule & Game Results")
games[0]
soup = BeautifulSoup(data.text, 'html5lib')
links = soup.find_all('a')
links =[l.get("href") for l in links]
links = [l for l in links if l and '/2023_advanced.htm' in l]
links
data = requests.get(f"https://www.pro-football-reference.com{links[0]}")
data.text
passing = pd.read_html(data.text, match="Advanced Passing")[0]
receiving = pd.read_html(data.text, match="Advanced Receiving")[0]
passing.head()
receiving.head()
Подробнее здесь: https://stackoverflow.com/questions/790 ... on-webpage