tag.previous_sibling and tag.find_previous_sibling() return different results
Bug #1799071 reported by
Alex Krupp
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Beautiful Soup |
Won't Fix
|
Undecided
|
Unassigned |
Bug Description
text = "<br>a<div>b</div>"
soup = BeautifulSoup(text, "lxml")
soup.div.
> 'a'
soup.div.
> <br/>
description: | updated |
summary: |
- tag.previous_sibling and tag.find_previous() return different results + tag.previous_sibling and tag.find_previous_sibling() return different + results |
To post a comment you must log in.
Thanks for filing this ticket. You've found a case where the defined behavior is confusing, but I don't think it's worth changing.
.previous_sibling is a fact about the parse tree. find_previous_ sibling( ) is a method call that invokes all the logic of the find* methods. The default behavior of the find* methods is to look only for tags. That's why find_previous_ sibling( ) with no arguments finds a tag.
It would also be reasonable if a find* method invoked with no arguments found _everything_, but that would break existing code, and if you want to find everything, you can use the generators, e.g. previous_siblings.