Appearance
可以通过 name 获取标签名。
代码:
from bs4 import BeautifulSoup html_content = ''' <div>测试01</div> <div>测试02</div> <h1>测试H1</h1> ''' soup = BeautifulSoup(html_content, 'html.parser') for ele in soup.find_all(['h1', 'h2', 'div']): print(ele.name)
执行结果:
div div h1