2017-06-17 57 views

回答

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> 

在我的機器。

+1

It works.Thank you very much! – AlphaGo

相關問題