Test if an attribute is present in a tag in BeautifulSoup

后端 未结 6 812
天涯浪人
天涯浪人 2020-12-07 22:01

I would like to get all the

6条回答
  •  臣服心动
    2020-12-07 22:40

    For future reference, has_key has been deprecated is beautifulsoup 4. Now you need to use has_attr

    scriptTags = outputDoc.findAll('script')
      for script in scriptTags:
        if script.has_attr('some_attribute'):
          do_something()  
    

提交回复
热议问题