How can I wrap <div data-role="content"></div> around the contents of html body with beautiful soup?
I tried to start with the following but haven't been able to make any progress:
from bs4 import BeautifulSoup
soup = BeautifulSoup(u"%s" % response)
wrapper = soup.new_tag('div', **{"data-role":"content"})
soup.body.append(wrapper)
for content in soup.body.contents:
wrapper.append(content)
I also tried using body.children but no luck.
This appends the wrapper to the body, but doesn't wrap the body contents like I need
-- edit --
I've gotten to here, but now I end up with duplicate body elements like this <body><div data-role="content"><body>content here</body></div></body>
from bs4 import BeautifulSoup
soup = BeautifulSoup(u"%s" % response)
wrapper = soup.new_tag('div', **{"data-role":"content"})
new_body = soup.new_tag('body')
contents = soup.body.replace_with(new_body)
wrapper.append(contents)
new_body.append(wrapper)