Is it possibile to modify a link value with Beautifulsoup without recreating the all link?
Posted
by systempuntoout
on Stack Overflow
See other posts from Stack Overflow
or by systempuntoout
Published on 2010-05-25T12:31:02Z
Indexed on
2010/05/25
17:41 UTC
Read the original article
Hit count: 158
python
|beautifulsoup
Starting from an Html input like this:
<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>
is it possible to modify the <a>
node values ("this i foo" and "this is bar") adding the suffix "PARSED" to the value without recreating the all link?
The result need to be like this:
<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>
And code should be something like:
from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup(html)
for link_tag in soup.findAll('a'):
link_tag.string = link_tag.string + '_PARSED' #This obviously does not work
© Stack Overflow or respective owner