我有麻烦下面的网页得到球员超链接网络刮,因为它只打印出从菜单在页面底部的球员,而不是列出的球员为相关的盒子得分游戏.我需要改变什么才能得到明尼苏达双胞胎和天使队的球员?
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.")