实际上,我正在使用BeautifulSoup。这段代码打印出类 main 的内容:
for text in soup.find_all("table", {'class', 'main'}):
txt += text
这已经是一件好事了,但是怎么可能还包括"开始标签",这是<class="main" ...>
?
非常感谢您的帮助! :)
你有一个集合而不是字典。做:
for text in soup.find_all("table", {'class':'main'}):
# ^ colon here instead of a comma
txt += text
for el in soup.findAll('table', {'class':'main'}):
print el.text # text is here
print el.attrs # all attributes is here