Multiple CSS class search is unhandy

Bug #1157869 reported by Romeno
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Beautiful Soup
Won't Fix
Undecided
Unassigned

Bug Description

Just discovered BS does not fully support searching for multiple CSS classes.

The quote from docs (http://www.crummy.com/software/BeautifulSoup/bs4/doc/#searching-by-css-class):
>> searching for variants of the string value won’t work:

css_soup.find_all("p", class_="strikeout body")
# []

To search html for more than one css class you need to do loops or build sophisticated regex.

Could you fix this behavior and make search for string "class1 class2" match tags containing BOTH of these classes or create another handy routine?

Searching css_soup.find_all("p", class_=["strikeout", "body"]) works like OR but not like AND.

The BeautifulSoup version is 4.1.3
Python 2.7.3
html5lib, lxml are not installed

Tags: class css find
Romeno (romenoex)
description: updated
description: updated
Revision history for this message
Leonard Richardson (leonardr) wrote :

You can use a CSS selector to search for a tag that matches several CSS classes. I've added this fact to the "searching bs CSS class" section of the documentation. This lets me resolve the issue without writing new code.

Changed in beautifulsoup:
status: New → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.