Reputation: 13
I am using the beautifulsoup4 in python in order to update the table on the confluence page when I use the soup.append(str) function, the < >
were escaped and became < >
so that i can not update the table correctly. Could someone give me tips? Or maybe some better solution for update the table on the confluence page, thanks in advance. :)
what i expect:
<tr>"string"</tr>
what the result:
<tr >"string"< tr>
Upvotes: 1
Views: 732
Reputation: 195408
That happens because you append string to other tag. The solution is to create new_tag()
or whole new soup.
For example:
txt = '''
<div>To this tag I append other tag</div>
'''
soup = BeautifulSoup(txt, 'html.parser')
soup.find('div').append( BeautifulSoup('<tr>string</tr>', 'html.parser') )
print(soup.prettify())
Prints:
<div>
To this tag I append other tag
<tr>
string
</tr>
</div>
Upvotes: 1