2017-06-17 6 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

作品です。ありがとうございました! – AlphaGo

関連する問題