I want to use Beautifulsoup to modify a whole div of a HTML. I was trying to modify the HTML, however the console output has the modifications, but the actual .
Two things:
This can be done as follows:
from bs4 import BeautifulSoup
import os
base = os.path.dirname(os.path.abspath(__file__))
html = open(os.path.join(base, 'example.html'))
soup = BeautifulSoup(html, 'html.parser')
for i in soup.find('div', {"id":None}).findChildren():
i.replace_with('##')
with open("example_modified.html", "wb") as f_output:
f_output.write(soup.prettify("utf-8"))