BeautifulSoup:打印出开始标签

时间:2013-09-09 11:20:07

标签: python beautifulsoup

实际上,我正在使用BeautifulSoup。此代码打印出类main的内容:

for text in soup.find_all("table", {'class', 'main'}):
        txt += text

这已经很好了,但是如何在<class="main" ...>中包含“开始标记”呢?

非常感谢您的帮助! :)

2 个答案:

答案 0 :(得分:1)

您有而不是字典。做:

for text in soup.find_all("table", {'class':'main'}):
#                                          ^ colon here instead of a comma
        txt += text

答案 1 :(得分:0)

for el in soup.findAll('table', {'class':'main'}):
    print el.text         # text is here
    print el.attrs        # all attributes is here