tags:

views:

35

answers:

1

I try to parse a secondary page with form . I use example code source from this link : http://blog.ianbicking.org/2007/09/24/lxmlhtml/ On my test i use this url: http://www.infofer.ro/ Like on example , I use this values :

>>> pprint(form.form_values())
[('cboData', '8/30/2010'),
 ('txtPlecare', 'Bucuresti Nord'),
 ('txtSosire', 'Constanta'),
 ('tip', 'GO'),
 ('lng', '1')]

The result is take it with this :

result = parse(submit_form(form)).getroot()

This is another page with another form . I try something like this :

>>> page2=parse(result).getroot()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/lxml/html/__init__.py", line 661, in parse
    return etree.parse(filename_or_url, parser, base_url=base_url, **kw)
  File "lxml.etree.pyx", line 2706, in lxml.etree.parse (src/lxml/lxml.etree.c:49945)
  File "parser.pxi", line 1525, in lxml.etree._parseDocument (src/lxml/lxml.etree.c:72026)
TypeError: cannot parse from 'HtmlElement'

How i parse the form from secondary page ?

Regards.

+1  A: 

The getroot method does not give you another "page", but an instance of lxml.html.HtmlElement.

There is no need (and no way) to parse this once more, you already have everything you need packed into the result variable.

jellybean