迭代BeautifulSoup对象

时间:2018-03-07 09:28:59

标签: python beautifulsoup

我正在迭代从html页面解析的表。我想遍历BeautifulSoup对象并在标记之间解析文本并将它们存储到列表中。但是,下面的代码只给出了迭代中的最后一个文本。如何在此问题中添加文本?​​

soup =  BeautifulSoup(webpage, 'html.parser')
table = soup.find("table",attrs={"id":"mvp_NBA"}).find("tbody").findAll("tr")

for row in table:
    key = []
    season = row.find_all("th")
    for year in season:
        y = year.get_text().encode('utf-8')
        key.append(y)
print key       

1 个答案:

答案 0 :(得分:0)

检查一下:

key=[]

你在你的列表Meteor.methods({ 'votes.insert': function (depute, loi, choix){ console.log('from votes.insert', depute, loi, choix) return Deputies.update(depute, {$push: {votes: {[loi]:choix}}} ); }, }); 的每次过程中你的for循环中唯一的错误就是我已经修改了你的代码并且它提供了你想要的输出。

相关问题