Maison  >  Questions et réponses  >  le corps du texte

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

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

大家讲道理大家讲道理2741 Il y a quelques jours885

répondre à tous(2)je répondrai

  • 天蓬老师

    天蓬老师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

    Comme ça ?

    répondre
    0
  • 伊谢尔伦

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

    h1.string

    répondre
    0
  • Annulerrépondre