I have a html file and i want to add a div tag after h1 tag. the div tag will have a anchor tag. how can i edit the existing html file using python and add the div with link this is what i want to do
<h1>
</h1>
<div> <a></a>
</div>
i tried with BeatifulSoup. got AttributeError: 'NoneType' object has no attribute 'insert_after' this error:
htmlFile ='path to html file'
soup = Soup(htmlFile)
headTag = soup.find('h1')
divTag = soup.new_tag('div')
divTag['class'] = "link"
headTag.insert_after(divTag)
pls suggest to modify this code to add the div tag in the current html file