我有一些html元素,我想从中提取文本。所以html就像
ZeroDivisionErrorTraceback (most recent call last)
<ipython-input-2-0f9f90da76dc> in <module>()
我要将文本提取为
ZeroDivisionErrorTraceback (most recent call last)
in()
我找到了针对该问题here的答案,但是它对我不起作用。完整的示例代码
from bs4 import BeautifulSoup as BSHTML
bs = BSHTML("""
ZeroDivisionErrorTraceback (most recent call last)
<ipython-input-2-0f9f90da76dc> in <module>()
""")print bs.font.contents[0].strip()
出现以下错误:
Traceback (most recent call last):
File "invest.py", line 13, in
print bs.font.contents[0].strip()
AttributeError: 'NoneType' object has no attribute 'contents'
我想念什么吗? beautifulsoap的版本:4.6.0