xpath question

Simon Forman rogue_pedro at yahoo.com
Sun Jul 2 21:26:30 EDT 2006


bruce wrote:
> simon..
>
> you may not.. but lot's of people use python and xpath for html/xml
> functionality.. check google "python xpath"...
>
> later..
>
...
> > i have a situation where i have something like:
> >  /html/table/..../[@class='foo']
> >
> > is it possible to do soomething like [@class~=/fo/] so i'd match the class
> > attribute with fo....
> >


So I did some checking, starting with the google search you suggested,
and I found out that lxml, 4Suite, and Amara (which is apparently based
on 4Suite somehow) all seem to be capable of doing what you're talking
about.  I don't know how to do it with lxml, but I bet the people on
the lxml mailing list would be happy to explain it to you.  As for
Amara and 4Suite I think it might be as simple as saying "Match(your
regex here in python re module form)" in your Xpath statement..


In the meantime, you could just use Xpath to extract a superset of the
elements you're interested in and then filter them with a re.Match
object.


I avoid xml if I can help it...   My new favorite HTML editor, however,
is python and ElementTree...




More information about the Python-list mailing list