我正在改编来自http://danielfrg.com/blog/2013/04/01/nba-scraping-data/#disqus_thread的网络抓取程序,以将 ESPN 的棒球数据抓取到 CSV 中。但是,当我运行第二段代码来编写一个 csv 游戏时,我从以下代码部分得到“NoneType”对象没有属性“find_all”错误
for index, row in teams.iterrows():
_team, url = row['team'], row['url']
r = requests.get(BASE_URL.format(row['prefix_1'], year, row['prefix_2']))
table = BeautifulSoup(r.text).table
for row in table.find_all("tr")[1:]: # Remove header
columns = row.find_all('td')
try:
_home = True if columns[1].li.text == 'vs' else False
_other_team = columns[1].find_all('a')[1].text
_score = columns[2].a.text.split(' ')[0].split('-')
_won = True if columns[2].span.text == 'W' else False
match_id.append(columns[2].a['href'].split('?id=')[1])
home_team.append(_team if _home else _other_team)
visit_team.append(_team if not _home else _other_team)
d = datetime.strptime(columns[0].text, '%a, %b …Run Code Online (Sandbox Code Playgroud)