Skip to content Skip to sidebar Skip to footer

Add Parent Tags With Beautiful Soup

I have many pages of HTML with various sections containing these code snippets:

Reference:

Copy

Simple example:

from bs4 import BeautifulSoup
soup = BeautifulSoup("<body><a>Some text</a></body>")
wrap(soup.a, soup.new_tag("b"))
print soup.body
# <body><b><a>Some text</a></b></body>

Example with your document:

for footnote in soup.find_all("div", "footnote"):
    new_tag = soup.new_tag("div")
    new_tag['class'] = 'footnote-out'wrap(footnote, new_tag)

Post a Comment for "Add Parent Tags With Beautiful Soup"