首頁  >  問答  >  主體

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

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

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

全部回覆(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
  • 取消回覆