BeautifulSoup - How to find a specific class name alone

前端 未结 3 556
闹比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 06:53

      Possibly with a filter function as in the doc

      def is_only_z(css_class):
          return css_class is not None and css_class == 'z'
      
      bs4.find_all('li',class_=is_only_z)
      

    提交回复
    热议问题