views:

46

answers:

1

Hello, I've got a form, returned by Python mechanize Browser and got via forms() method. How can I perform XPath search inside form node, that is, among descendant nodes of the HTML form node? TIA

Upd: How to save html code of the form?

+1  A: 

By parsing the browser contents with lxml, which has xpath support.

Lennart Regebro
so you mean the parser used by mechanize doesn't support xpath? (which one is that, btw?)
roddik
A quick look through in the source says it uses regexp to find links and ClientForm to find forms. ClientForm in turn seems to use sgmllib. There is no xml anywhere in sight. :)
Lennart Regebro
Looks like form_parser_class is used to parse forms, which is set to ClientForm.FormParser if None is used to initialize the factory, but maybe it's possible to set it to another parser, like a wrapper around ClientForm.FormParser which would at least save source html for form?
roddik
Seems easier to just parse the source directly than rebuild the FormParser. But yeah, I guess it could work.
Lennart Regebro