I have trouble with the webpage below getting the player hyperlinks web scraped as it only prints out players from the menu at the bottom of the page, rather than the players listed for the relevant box score game. What needs to change so that I can get the players for the Minnesota Twins and Angels as listed?
import requests
from bs4 import BeautifulSoup
# URL of the webpage
url = "https://www.baseball-reference.com/boxes/ANA/ANA202305210.shtml"
# Send a GET request to the webpage
response = requests.get(url)
# Check if the request was successful
if response.status_code == 200:
# Parse the HTML content of the webpage using BeautifulSoup
soup = BeautifulSoup(response.content, 'html.parser')
# Find all hyperlink elements on the page with "/players/" in the href attribute
links = soup.find_all('a', href=lambda href: href and '/players/' in href)
# Extract and print the href attribute of each matching hyperlink
for link in links:
href = link.get('href')
print(href)
else:
print("Failed to fetch the webpage.")