Я новичок в красивом супе и искал способ, чтобы пользователь ввел, какую команду они хотели и на какой неделе. Затем попросите сценарий распечатать определенную статистику за эту неделю. В выводе, когда я ввожу команду и номер недели, он просто попадает прямо в командную строку.
Вот мой код:
import requests
from bs4 import BeautifulSoup
team = input('''What team are you looking for?
crd - Arizona Cardinals
atl - Atlanta Falcons
rav - Baltimore Ravens
buf - Buffalo Bills
car - Carolina Panthers
chi - Chicago Bears
cin - Cincinnati Bengals
cle - Cleveland Browns
dal - Dallas Cowboys
den - Denver Broncos
det - Detroit Lions
gnb - Green Bay Packers
htx - Houston Texans
clt - Indianapolis Colts
jax - Jacksonville Jaguars
kan - Kansas City Chiefs
sdg - Los Angeles Chargers
ram - Los Angeles Rams
mia - Miami Dolphins
min - Minnesota Vikings
nwe - New England Patriots
nor - New Orleans Saints
nyg - New York Giants
nyj - New York Jets
rai - Oakland Raiders
phi - Philadelphia Eagles
pit - Pittsburgh Steelers
sfo - San Fransisco 49ers
sea - Seattle Seahawks
tam - Tampa Bay Buccaneers
oti - Tennessee Titans
was - Washington Football Team
Enter the 3 letter code for the team: ''')
week = int(input('What week are you looking for? '))
url = 'https://www.pro-football-reference.com/teams/' + team.lower() + '/2019.htm'
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
week_num = soup.find_all('th', attrs={"data-stat": "week_num", "class": "right", "scope": "row"})
total_off = soup.find_all('td', attrs={"data-stat": "yards_off", "class": "right"})
total_def = soup.find_all('td', attrs={"data-stat": "yards_def", "class": "right"})
pass_yards_off = soup.find_all('td', attrs={"data-stat": "pass_yds_off", "class": "right"})
pass_yards_def = soup.find_all('td', attrs={"data-stat": "pass_yds_def", "class": "right"})
rush_yards_off = soup.find_all('td', attrs={"data-stat": "rush_yds_off", "class": "right"})
rush_yards_def = soup.find_all('td', attrs={"data-stat": "rush_yds_def", "class": "right"})
team_score = soup.find_all('td', attrs={"data-stat": "pts_off", "class": "right"})
opp_score = soup.find_all('td', attrs={"data-stat": "pts_def", "class": "right"})
for i in range(len(week_num)):
if week in week_num:
print('Week Number: ' + week_num[i].text.strip(),
'Total Off: ' + total_off[i].text.strip(),
'Total Def: ' + total_def[i].text.strip(),
'Passing Yards Off: ' + pass_yards_off[i].text.strip(),
'Passing Yards Def: ' + pass_yards_def[i].text.strip(),
'Rushing Yards Off: ' + rush_yards_off[i].text.strip(),
'Rushing Yards Def: ' + rush_yards_def[i].text.strip(), '\n')
Вот результат, когда я его запускаю:
What team are you looking for?
crd - Arizona Cardinals
atl - Atlanta Falcons
rav - Baltimore Ravens
buf - Buffalo Bills
car - Carolina Panthers
chi - Chicago Bears
cin - Cincinnati Bengals
cle - Cleveland Browns
dal - Dallas Cowboys
den - Denver Broncos
det - Detroit Lions
gnb - Green Bay Packers
htx - Houston Texans
clt - Indianapolis Colts
jax - Jacksonville Jaguars
kan - Kansas City Chiefs
sdg - Los Angeles Chargers
ram - Los Angeles Rams
mia - Miami Dolphins
min - Minnesota Vikings
nwe - New England Patriots
nor - New Orleans Saints
nyg - New York Giants
nyj - New York Jets
rai - Oakland Raiders
phi - Philadelphia Eagles
pit - Pittsburgh Steelers
sfo - San Fransisco 49ers
sea - Seattle Seahawks
tam - Tampa Bay Buccaneers
oti - Tennessee Titans
was - Washington Football Team
Enter the 3 letter code for the team: nwe
What week are you looking for? 6