How to Beautiful Soup (bs4) match just one, and only one, css class

后端 未结 7 632
说谎
说谎 2020-12-10 20:28

I am using following code to match all div that have CSS class \"ad_item\".

soup.find_all(\'div\',class_=\"ad_item\")

problem that I have i

7条回答
  •  天涯浪人
    2020-12-10 20:39

    You can use strict conditions like this:

    soup.select("div[class='ad_item']")
    

    That catch div with exact class. In this case with only 'ad_item' and no others joined by spaces classes.

提交回复
热议问题