Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrapy - Submit form with multiple buttons

I'm starting to work with scrapy and I managed to crawl through a series of forms, but the last form has two buttons, reject and accept.

<input name="_eventId_AttributeReleaseRejected" style="margin-right: 30px;" type="submit" value="Reject"> 
<input name="_eventId_proceed" type="submit" value="Accept">

How do I tell scrapy to choose Accept ? I used this code

def thirdForm(self, response):
    yield FormRequest.from_response(response, 
        formname="Form",
        callback=self.parseResponse)

but it chooses reject by default, How can I get past this ?

like image 379
Zeyad Obaia Avatar asked Sep 06 '25 03:09

Zeyad Obaia


1 Answers

I found out how to do it, you can specify which button to submit using a property called clickdata It's a python dictionary containing the name and/or the value of the button you want to submit.

Here's the code after editing

def thirdForm(self, response):
        yield FormRequest.from_response(response, 
            formname="Form",
            clickdata={"name":"_eventId_proceed", 'value' :'Accept'},
            callback=self.parseResponse)
like image 57
Zeyad Obaia Avatar answered Sep 08 '25 00:09

Zeyad Obaia