How to extract h1 tag text with beautifulsoup

前端 未结 2 1031
温柔的废话
温柔的废话 2021-01-06 12:01

I\'d like to understand how to extract a h1 tag text which contains many others tags in it using beautiful soup :

2条回答
  •  醉话见心
    2021-01-06 12:15

    Try using a dictionary:

    company = soup.find('h1', {'class' : 'listing-name'})
    

    Or the following:

    company = soup.find('h1', class_ ='listing-name')
    

    Note the underscore after class. This is because class is a reserved word in python.

    More info can be found here: https://www.crummy.com/software/BeautifulSoup/bs4/doc/#attrs

提交回复
热议问题