From 121d7535beb327d1d63a92ae39b9974d8eec7bb3 Mon Sep 17 00:00:00 2001 From: Olaf Dietsche Date: Sat, 11 Jul 2015 16:11:31 +0200 Subject: [PATCH] Allow button cotrols to submit form --- scrapy/http/request/form.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scrapy/http/request/form.py b/scrapy/http/request/form.py index 0b1d3b926..1920cefe1 100644 --- a/scrapy/http/request/form.py +++ b/scrapy/http/request/form.py @@ -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))