How to find links and modify an Html using BeautifulSoup in Python

Posted by systempuntoout on Stack Overflow See other posts from Stack Overflow or by systempuntoout
Published on 2010-05-24T21:12:57Z Indexed on 2010/05/24 21:31 UTC
Read the original article Hit count: 221

Filed under:
|

Starting from an Html input like this:

<p>
<a href="http://www.foo.com">this if foo</a>
<a href="http://www.bar.com">this if bar</a>
</p>

using BeautifulSoup, i would like to change this Html in:

<p>
<a href="http://www.foo.com">this if foo[1]</a>
<a href="http://www.bar.com">this if bar[2]</a>
</p>

saving parsed links in a dictionary with a result like this:

links_dict = {"1":"http://www.foo.com","2":"http://www.bar.com"}

Is it possible to do this using BeautifulSoup? Any valid alternative?

© Stack Overflow or respective owner

Related posts about python

Related posts about beautifulsoup