【发布时间】:2018-02-23 17:14:56
【问题描述】:
我正在尝试创建一个程序,该程序从各个网站获取 nba 球队数据,并以列表的形式为每个球队编译统计数据。
IE:亚特兰大 = ['107.5','105.6','.516','.543']
数字表示场均得分、对手场均得分、RPI 和篮板率。
我现在遇到了一个错误,只是想弄清楚如何获取用户输入,在列表列表中找到该团队的列表,并从该列表中提取某个索引。
import urllib.request
from bs4 import BeautifulSoup
soup = BeautifulSoup(urllib.request.urlopen("http://www.espn.com/nba/stats/rpi"), "lxml")
data = [[x.text for x in row.find_all("td")] for row in soup.select("table tr")]
tables = []
team_s = []
for row in data:
tables.append(row)
team_s = [item[0] for item in tables]
team_s = [el.replace('\xa0',' ') for el in team_s]
print (team_s[2])
print ("-" * 80)
print ("Welcome to the NBA betting helper. \nTo start, enter the city of the home team for team 1. Then enter the city of the away team for team 2.")
print ("-" * 80)
home = input("Enter the city of team 1 (Home Team):")
away = input("Enter the city of team 2 (Away Team):")
Atlanta = []
Boston = []
try:
print (team_s.index("Detroit"))
except ValueError:
print ("word1 not in list.")
def hometeam():
print ("ex")
def awayteam():
print ("ex")
#Main
hometeam()
awayteam()
【问题讨论】:
-
我在表格中看不到反弹百分比列。你这是什么意思?
-
"I'm running into an error right now",那个错误是……? -
对不起,我也在使用这个链接:espn.com/nba/statistics/team/_/stat/team-comparison-per-game 但错误是当我去索引子列表时,我发现它超出了范围。不过我现在已经准备好了。
标签: python python-3.x list beautifulsoup sublist