mirror of https://github.com/scrapy/scrapy.git
Allow button cotrols to submit form
This commit is contained in:
parent
e5f26078fa
commit
121d7535be
|
|
@ -150,14 +150,16 @@ def _get_clickable(clickdata, form):
|
|||
if the latter is given. If not, it returns the first
|
||||
clickable element found
|
||||
"""
|
||||
clickables = [el for el in form.xpath('.//input[@type="submit"]')]
|
||||
clickables = [el for el in form.xpath('descendant::input[@type="submit"]'
|
||||
'|descendant::button[@type="submit"]'
|
||||
'|descendant::button[not(@type)]')]
|
||||
if not clickables:
|
||||
return
|
||||
|
||||
# If we don't have clickdata, we just use the first clickable element
|
||||
if clickdata is None:
|
||||
el = clickables[0]
|
||||
return (el.name, el.value)
|
||||
return (el.get('name'), el.get('value'))
|
||||
|
||||
# If clickdata is given, we compare it to the clickable elements to find a
|
||||
# match. We first look to see if the number is specified in clickdata,
|
||||
|
|
@ -169,7 +171,7 @@ def _get_clickable(clickdata, form):
|
|||
except IndexError:
|
||||
pass
|
||||
else:
|
||||
return (el.name, el.value)
|
||||
return (el.get('name'), el.get('value'))
|
||||
|
||||
# We didn't find it, so now we build an XPath expression out of the other
|
||||
# arguments, because they can be used as such
|
||||
|
|
@ -177,7 +179,7 @@ def _get_clickable(clickdata, form):
|
|||
u''.join(u'[@%s="%s"]' % c for c in six.iteritems(clickdata))
|
||||
el = form.xpath(xpath)
|
||||
if len(el) == 1:
|
||||
return (el[0].name, el[0].value)
|
||||
return (el[0].get('name'), el[0].get('value'))
|
||||
elif len(el) > 1:
|
||||
raise ValueError("Multiple elements found (%r) matching the criteria "
|
||||
"in clickdata: %r" % (el, clickdata))
|
||||
|
|
|
|||
Loading…
Reference in New Issue