试图找出为什么我没有得到我想要的东西。以下是我的代码:
source = urllib.request.urlopen('http://www.espn.com/college-football/team/schedule/_/id/2132').read()
soup = bs.BeautifulSoup(source, "lxml")
date_list = []
for table in soup.find("div", {"class": "mod-content"}):
for game in table.find_all("tr", {"class": ["oddrow", "evenrow"]}):
for date in game.find('td'):
date_list.append(date)
for opponent in game.find_all("ul", {"class": "game-schedule"}):
print(opponent)
查看源代码,在同一级别的汤中实际上有两个<ul class="game-schedule">
(兄弟姐妹??)。当我运行上面的代码时,似乎我只是输入第一个并且只从第一个元素中检索数据。我还需要输入send一个来解析该元素。我在想find_all
找到指定的每个元素。我还需要做什么才能输入第二个<ul class="game-schedule">
元素??
我想做类似的事情:
for opponent in game.find_all(1ST GAME-SCHEDULE):
DO STUFF IN FIRST GAME-SCHEDULE
for result in game.find_all(2ND GAME-SCHEDULE):
DO STUFF IN SECOND GAME-SCHEDULE
答案 0 :(得分:0)
我是个白痴。我在源变量中输入了错误的URL。所以我在浏览器中查看了一个页面,但试图在BS中删除另一个页面。杜!