У меня возникли проблемы с веб-страницей, приведенной ниже, при очистке гиперссылок игроков, поскольку она распечатывает только игроков из меню внизу страницы, а не игроков, перечисленных для соответствующей игры с очками. Что нужно изменить, чтобы я мог получить игроков «Миннесота Твинс и Энджелс», как указано в списке?
import requests
from bs4 import BeautifulSoup
# URL of the webpage
url = "https://www.baseball-reference.com/boxe ... 5210.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.")
Подробнее здесь: https://stackoverflow.com/questions/769 ... -box-score