What is the most efficient way to insert an element as last one in the body
of an HTML page?
A new tag can be created by calling BeautifulSoup's inbuilt function new_tag(). Inserting a new tag using the append() method : The new tag is appended to the end of the parent tag.
decompose() removes a tag from the tree of a given HTML document, then completely destroys it and its contents.
See my answer to a previous question along the same lines:
The following should insert just fine:
soup.body.insert(len(soup.body.contents), yourelement)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With