Code: Select all
for year in years:
data = requests.get(standing_url)
soup = BeautifulSoup(data.text)
standing_table = soup.select("table.stats_table")[0]
links = standing_table.find_all("a")
links = [I.get("href") for I in links]
links = [I for I in links if "/squads/" in I]
team_urls = [f"https//fbref.com{I}" for I in links]
for team_url in team_urls:
team_name = team_url.split("/")[-1].replace("-Stats","").replace("-"," ")
data = requests.get(team_url)
matches = pd.read_html(data.text, match = "Scores & Fixtures")[0]
soup = BeautifulSoup(data.text)
links = soup.find_all("a")
links = [I.get("href") for I in links]
links = [I for I in links if I and "all_comp/shooting/" in I]
data = requests.get(f"https://fbref.com{links[0]}")
shooting = pd.read_html(data.text, match = "Shooting")[0]
shooting.columns = shooting.columns.droplevel()
Code: Select all
# MissingSchema: Invalid URL 'https//fbref.com/en/squads/18bb7c10/Arsenal-Stats': No scheme supplied. Perhaps you meant http://https//fbref.com/en/squads/18bb7c10/Arsenal-Stats?
Mobile version