diff options
Diffstat (limited to 'bs4/element.py')
-rw-r--r-- | bs4/element.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/bs4/element.py b/bs4/element.py index e4f2303..5ee9887 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -319,6 +319,14 @@ class PageElement(object): and not isinstance(new_child, NavigableString)): new_child = NavigableString(new_child) + from bs4 import BeautifulSoup + if isinstance(new_child, BeautifulSoup): + # We don't want to end up with a situation where one BeautifulSoup + # object contains another. Insert the children one at a time. + for subchild in list(new_child.contents): + self.insert(position, subchild) + position += 1 + return position = min(position, len(self.contents)) if hasattr(new_child, 'parent') and new_child.parent is not None: # We're 'inserting' an element that's already one |