game_link = "http://espn.go.com/nba/playbyplay?gameId=400579510&period=0"
game_source = urlopen(game_link)
game_html = game_source.read()
game_source.close();
row = BeautifulSoup(game_html, "html.parser")
pieces = list(row.children)
我需要从上面的链接得到游戏日志行,但是上面的代码给了我完整的HTML文本,我怎样才能提取表并将它们转换成单行(片段)
您可以尝试
BeautifulSoup.findAll
并提供标签以及您可能知道的有关您要查找的标签的任何其他属性。在查看页面之后,看起来您正在查找所有带有类even
的<tr>
标记。所以你可以用soup.findAll("tr", attrs = {"class": "even"})
。例如您仍然需要解析每一行的html。下面是一个非常“粗糙”的例子
相关问题 更多 >
编程相关推荐