Beautifulsoup multiple class selector

前端 未结 5 1964
青春惊慌失措
青春惊慌失措 2020-12-05 07:20

I want to select all the divs which have BOTH A and B as class attributes.

The following selection

soup.findAll(\'div\', class_=[\'A\', \'B\'])
         


        
5条回答
  •  执笔经年
    2020-12-05 08:02

    1 some tag like:

    XXXX
    

    if you want to use CSS selector to get the tag, you can write the code for the class attribute as following:

    spans = beautifulsoup.select('span.A.B.C.D')
    

    2 And if you want to use this for id attribute, you change as following:

    XXXX
    

    change the symbol you use in select function:

    span = beautifulsoup.select('span#A')
    

    What we learn is that its grammer is like the CSS3

提交回复
热议问题