tag.previous_sibling and tag.find_previous_sibling() return different results

Bug #1799071 reported by Alex Krupp
6
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.previous_sibling
> 'a'

soup.div.find_previous_sibling()
> <br/>

Alex Krupp (alex3917)
description: updated
summary: - tag.previous_sibling and tag.find_previous() return different results
+ tag.previous_sibling and tag.find_previous_sibling() return different
+ results
Revision history for this message
Leonard Richardson (leonardr) wrote :

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.

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.