Beautiful Soup cannot find a CSS class if the object has other classes, too

后端 未结 4 1761
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 18:13

if a page has

and

, then soup.findAll(True, \'class1\') will find them both.

4条回答
  •  鱼传尺愫
    2020-11-27 18:16

    Just in case anybody comes across this question. BeautifulSoup now supports this:

    Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)]
    Type "copyright", "credits" or "license" for more information.
    
    In [1]: import bs4
    
    In [2]: soup = bs4.BeautifulSoup('
    ') In [3]: soup(attrs={'class': 'bar'}) Out[3]: [
    ]

    Also, you don't have to type findAll anymore.

提交回复
热议问题