python的bs4库中如何筛选出SEO h1标签中内容,bs4seo,今天在学习bs4的解析h


今天在学习bs4的解析html中 发现有解析各种标签中的内容的语句,但是未找到能解析出h1 h2 h3 h4这些标签中的文字的语句和参数啊,请问该如何进行筛选呢?

>>> from bs4 import BeautifulSoup>>> html = """    <html>    <h1 align="center">This is heading 1</h1>    </html>    """>>> soup = BeautifulSoup(html,'html.parser')>>> res = soup.find('h1').get_text()>>> print(res)This is heading 1

像这样吗?

h1.string

编橙之家文章,

评论关闭