diff options
Diffstat (limited to 'bs4/element.py')
-rw-r--r-- | bs4/element.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/bs4/element.py b/bs4/element.py index 7c787b1..d1b7c12 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -261,17 +261,20 @@ class PageElement(object): last_child = self._last_descendant() next_element = last_child.next_element - if self.previous_element is not None: + if (self.previous_element is not None and + self.previous_element != next_element): self.previous_element.next_element = next_element - if next_element is not None: + if next_element is not None and next_element != self.previous_element: next_element.previous_element = self.previous_element self.previous_element = None last_child.next_element = None self.parent = None - if self.previous_sibling is not None: + if (self.previous_sibling is not None + and self.previous_sibling != self.next_sibling): self.previous_sibling.next_sibling = self.next_sibling - if self.next_sibling is not None: + if (self.next_sibling is not None + and self.next_sibling != self.previous_sibling): self.next_sibling.previous_sibling = self.previous_sibling self.previous_sibling = self.next_sibling = None return self |