BeautifulSoup - How to find a specific class name alone

前端 未结 3 549
闹比i
闹比i 2021-02-10 06:31

How to find the li tags with a specific class name but not others? For example:

...
  • no wanted
  • not his
  • 3条回答
    •  温柔的废话
      2021-02-10 07:06

      You can simply do:

      data = soup.find_all('li',{'class':'z'})
      print(data)
      

      If you only want to get text:

      for a in data:
         print(a.text)
      

    提交回复
    热议问题