1
0
mirror of https://github.com/scrapy/scrapy.git synced 2025-03-02 20:48:45 +00:00

Update form.py to improve existing capability

Add capability to search HTML Form using formid when using `FormRequest.from_response()`

refrenced issue :https://github.com/scrapy/scrapy/issues/1136
This commit is contained in:
Dharmesh Pandav 2015-04-06 14:44:47 +05:30
parent 9706119336
commit 5a96a16914

View File

@ -31,10 +31,10 @@ class FormRequest(Request):
self._set_url(self.url + ('&' if '?' in self.url else '?') + querystr)
@classmethod
def from_response(cls, response, formname=None, formnumber=0, formdata=None,
def from_response(cls, response, formname=None, formid=None, formnumber=0, formdata=None,
clickdata=None, dont_click=False, formxpath=None, **kwargs):
kwargs.setdefault('encoding', response.encoding)
form = _get_form(response, formname, formnumber, formxpath)
form = _get_form(response, formname, formid, formnumber, formxpath)
formdata = _get_inputs(form, formdata, dont_click, clickdata, response)
url = _get_form_url(form, kwargs.pop('url', None))
method = kwargs.pop('method', form.method)
@ -67,6 +67,11 @@ def _get_form(response, formname, formnumber, formxpath):
if f:
return f[0]
if formid is not None:
f = root.xpath('//form[@id="%s"]' % formid)
if f:
return f[0]
# Get form element from xpath, if not found, go up
if formxpath is not None:
nodes = root.xpath(formxpath)