当使用BeautifulSoup解析HTML文档时,如果遇到空的class属性,需要将空的class属性赋值为None。下面是代码示例:
from bs4 import BeautifulSoup html = '' soup = BeautifulSoup(html, 'html.parser') div = soup.find('div', {'class': None}) # 将空的class属性赋值为None print(div)
输出结果为:
上一篇:BeautifulSoup问题和html5lib卸载安装问题
下一篇:BeautifulSoupwithemptyclassname。