我有下面的beautifulsouphtml标记,我想将标记中的文本TEXT TO BE UPDATED
更新为SOMETHING ELSE
。你知道吗
<p><img src="./img.jpg"> TEXT TO BE UPDATED.</p>
假设上面<p>
标记的Beautifulsoup对象是p_tag
。我试图使用p_tag.string.replace_with('SOMETHING ELSE')
,但它不起作用,因为p_tag.string
总是返回None
。知道为什么吗?你知道吗
Tags:
您需要使用
p_tag.text
来获取文本,使用p_tag.string
来设置新文本。你知道吗像这样:
相关问题 更多 >
编程相关推荐