html parsing

Fredrik Lundh fredrik at pythonware.com
Tue Apr 9 03:27:51 EDT 2002


Randy Heiland wrote:
> I'm a newbie at parsing html in Python... could someone offer a snippet
> of code to:
> 1) specify a URL
> 2) parse the html and return the hyperlink associated with a unique
> anchor string

the htmllib-example-1 script almost does what you want.

    http://www.oreilly.com/catalog/pythonsl/chapter/ch05.html#t5

to read from an url, replace the "open" call with a
call to "urllib.urlopen".

to get the link for a given text, just look it up in the
anchors dictionary.

hope this helps!

</F>

<!-- (the eff-bot guide to) the python standard library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->





More information about the Python-list mailing list