diff options
author | Leonard Richardson <leonardr@segfault.org> | 2023-01-25 14:50:44 -0500 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2023-01-25 14:50:44 -0500 |
commit | 9f29d5b62539d8020b3e99e084c52a45996b7403 (patch) | |
tree | f0b475ecbbf521c8716e7cd9676b4aa34169d8d2 /bs4/element.py | |
parent | e4f967730af7d5ea59f6a05d03c779df16a24bd3 (diff) |
Passing a Tag's .contents into PageElement.extend() now works the
same way as passing the Tag itself.
Diffstat (limited to 'bs4/element.py')
-rw-r--r-- | bs4/element.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/bs4/element.py b/bs4/element.py index 74b1dc0..98e978f 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -496,13 +496,16 @@ class PageElement(object): def extend(self, tags): """Appends the given PageElements to this one's contents. - :param tags: A list of PageElements. + :param tags: A list of PageElements. If a single Tag is + provided instead, this PageElement's contents will be extended + with that Tag's contents. """ if isinstance(tags, Tag): - # Calling self.append() on another tag's contents will change - # the list we're iterating over. Make a list that won't - # change. - tags = list(tags.contents) + tags = tags.contents + if isinstance(tags, list): + # Moving items around the tree may change their position in + # the original list. Make a list that won't change. + tags = list(tags) for tag in tags: self.append(tag) |