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):
"""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:
try:
self.parent.contents.remove(self)
except ValueError:
pass
idx = None
for i, x in enumerate(self.parent.contents):
if x is self:
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
#this element (and any children) hadn't been parsed. Connect