首页  >  问答  >  正文

python的bs4如何筛选出h1标签中的内容

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

大家讲道理大家讲道理2741 天前886

全部回复(2)我来回复

  • 天蓬老师

    天蓬老师2017-04-18 10:23:14

    >>> 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

    像这样吗?

    回复
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:23:14

    h1.字符串

    回复
    0
  • 取消回复