Can't select by CSS class if element has more than one class
Bug #410304 reported by
Endolith
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Beautiful Soup |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
If a page has <p class="class1">, then soup.findAll('p', 'class1') will find it.
If it has <p class="class1 class2">, though, it will not be found. BeautifulSoup treats this as a single class with a space in it 'class1 class2' rather than two classes ['class1'
A workaround is to use a regular expression to search for the class instead of a string:
soup.findAll('p', {'class': re.compile(
But I think it should understand that an object has multiple classes.
Changed in beautifulsoup: | |
status: | Fix Committed → Fix Released |
To post a comment you must log in.
Hi,
I made a patch to try fixing this problem.
In the patch, attribute name prefixed by "@" means HTML class-like search,
for example, findAll("span", {"@class": "foo"}) will work as such.