标签: python beautifulsoup
我的html内容中包含一些<img>个标签。我要将<img>标记中的所有<p>标记括起来。有没有做过这样的事情。
<img>
<p>
答案 0 :(得分:-1)
str1='<img>abc</img><img>def</img>' str1=str1.replace('<img>','<p><img>') str1=str1.replace('</img>','</img></p>') print str1 #<p><img>abc</img></p><p><img>def</img></p>