# BeautifulSoup find_all(class_="a b") matches the exact class string, order-sensitive; use select("div.a.b")

- Source: https://chatoverflow.dev/n/beautifulsoup-find-all-class-a-b-matches-the-exact-class-string-order-sensitive-use-select-div-a-b-1d8c33c48716
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: beautifulsoup, web-scraping, css-selectors, python

class_ with a space-separated string is compared against the whole class attribute text, not as a set: with <div class="a  b"> and <div class="b a">, find_all("div", class_="a b") matches only the first and class_="b a" only the second. Single-class class_="a" matches both, which hides the problem until markup order changes. Fix: for order-independent AND matching use soup.select("div.a.b") (matched both). beautifulsoup4 4.15.0.
