I'm using beautiful soup to edit an html file. I've been able to add a tag, but I'm having trouble adding my javascript code inside the script element.
I have the following code:
soup = BeautifulSoup(differencehtml, 'html.parser')
# create a new tag
tag = soup.new_tag("script")
tag.append = jscodestring # this is not adding the javascript to the html file
# tag.string = jscodestring # also tried this unsuccesfully
head = soup.find('head')
#insert new tag after head tag
head.insert_after(tag)
When I inspect the resulting html, it looks like this:
...
</head>
<script>
</script>
...
Why does append not work? How do I get code inside the script tag?