is there an equivalent for tag.innerHTML += x in BS4?

Viewed 45

When I try to use e.string to modify HTML in BS4, I get HTML entities. For example:

Code:

for i in soup.find_all('ism'):
    i.string = currentSpan
    # currentSpan is a string of HTML text and does not have entities

Result

<span>Keep going until you see </span><ism type="cr">&lt;span style="color: gold; background: blue; border-style: double; padding-left: 5px; padding-right: 5px;"&gt;County Road 9&lt;/span&gt;</ism>

(ism is a custom tag name I am using).

Is there a function I can use to add tags and override entity conversion?

1 Answers

Nevermind, I answered it myself.

There's this property called 'tag.contents' which is a Tag that represents the HTML of the element.

To modify the HTML, I typed,

el.contents = BeautifulSoup(your_html, 'html.parser')

and that seemed to work.

Related