BeautifulSoup: Fix bug in extract() method that prevented extraction of identical individual tags

This commit is contained in:
Kovid Goyal 2010-04-16 15:44:22 +05:30
parent a031f04e91
commit 9fa6e8abe2

View File

@ -129,11 +129,16 @@ class PageElement:
def extract(self): def extract(self):
"""Destructively rips this element out of the tree.""" """Destructively rips this element out of the tree."""
# Changed by KG as list.remove uses _-eq__ which is True for two Tags
# with the same name and attributes.
if self.parent: if self.parent:
try: idx = None
self.parent.contents.remove(self) for i, x in enumerate(self.parent.contents):
except ValueError: if x is self:
pass idx = i
break
if idx is not None:
self.parent.contents.pop(idx)
#Find the two elements that would be next to each other if #Find the two elements that would be next to each other if
#this element (and any children) hadn't been parsed. Connect #this element (and any children) hadn't been parsed. Connect