<>是自动编码。
请帮助我,谢谢。
答案 0 :(得分:0)
您可以使用Tag.new_tag(..)
,Tag.clear()
和Tag.append()
以更具语义的方式执行此操作:
atag = soup.a
atag.clear() # clear the content of the <a> tag
atag.append('support') # add the 'support' text
emtag = soup.new_tag('em') # create a new <em> tag
atag.append(emtag) # add the <em> tag to the <a> tag
emtag.string = '[6666]' # alter the text in the <em> tag
这构造:
>>> soup
<html><body><a href="#" onclick="foo">support<em>[6666]</em></a></body></html>
在我的机器上。