String parsing

Carsten Haese carsten at uniqsys.com
Tue May 8 22:40:15 EDT 2007


On 8 May 2007 19:06:14 -0700, HMS Surprise wrote
> Thanks for posting. Could you reccommend an HTML parser that can be
> used with python or jython?

BeautifulSoup (http://www.crummy.com/software/BeautifulSoup/) makes HTML
parsing easy as pie, and sufficiently old versions seem to work with Jython. I
just tested this with Jython 2.2a1 and BeautifulSoup 1.x:

Jython 2.2a1 on java1.5.0_07 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> from BeautifulSoup import BeautifulSoup
>>> soup = BeautifulSoup("""<input type="hidden" name="LastUpdated"    
value="1178658863"/>""")
>>> print soup.first('input', {'name':'LastUpdated'}).get('value')
1178658863

Hope this helps,

--
Carsten Haese
http://informixdb.sourceforge.net




More information about the Python-list mailing list