I have to copy a part of one document to another, but I don\'t want to modify the document I copy from.
If I use .extract()
it removes the element from
It may not be the fastest solution, but it is short and seems to work...
clonedtag = BeautifulSoup(str(sourcetag)).body.contents[0]
BeautifulSoup creates an extra ...
around the cloned tag (in order to make the "soup" a sane html document). .body.contents[0]
removes those wrapping tags.
This idea was derived Peter Woods comment above and Clemens Klein-Robbenhaar's comment below.