Python 是否可以使用Beautifulsoup修改链接值而不重新创建所有链接?

Python 是否可以使用Beautifulsoup修改链接值而不重新创建所有链接?,python,beautifulsoup,Python,Beautifulsoup,从如下Html输入开始: <p> <a href="http://www.foo.com" rel="nofollow">this is foo</a> <a href="http://www.bar.com" rel="nofollow">this is bar</a> </p> <p> <a href="http://www.foo.com" rel="nofollow">this is foo

从如下Html输入开始:

<p>
<a href="http://www.foo.com" rel="nofollow">this is foo</a>
<a href="http://www.bar.com" rel="nofollow">this is bar</a>
</p>
<p>
<a href="http://www.foo.com" rel="nofollow">this is foo_PARSED</a>
<a href="http://www.bar.com" rel="nofollow">this is bar_PARSED</a>
</p>

如果我理解正确,你就快到了。 将代码更改为

for link_tag in soup.findAll('a'):
    link_tag.string = link_tag.string + '_PARSED'
html_out = soup.renderContents()
如果我们打印出html,我们会得到:

>>> print html_out
<p>
<a href="http://www.foo.com" rel="nofollow">this is foo_PARSED</a>
<a href="http://www.bar.com" rel="nofollow">this is bar_PARSED</a>
</p>
>>打印html\u


我想这正是你想要的。

@systempuntoot,你确定吗?这对我来说很好用。我用的是3.0.8.1版。我用的是DarwinPort下载的3.07a版。与3.08的作品像一个魅力:)谢谢。
>>> print html_out
<p>
<a href="http://www.foo.com" rel="nofollow">this is foo_PARSED</a>
<a href="http://www.bar.com" rel="nofollow">this is bar_PARSED</a>
</p>