Selecting options from a drop-down menu with scrapy

2,610 views
Skip to first unread message

Andrew Jirotka

unread,
Aug 22, 2014, 1:22:08 PM8/22/14
to scrapy...@googlegroups.com

Hi there,

I need to complete a simple form with scrapy, but I just can't figure out how to fill it out and submit it.

Here is the HTML of the form:

<form action="#" id="historicalQuoteDatePicker" class="ZEITRAUM" method="get">
    <fieldset> 
        <label for="dateStart">Startdatum:</label>
        <input type="text" name="dateStart" id="dateStart" value="" class="hasDatepicker">
        <img class="ui-datepicker-trigger" src="http://i.onvista.de/d.gif" alt="Klicken Sie hier um ein Datum auszuwählen" title="Klicken Sie hier um ein Datum auszuwählen"> 
        <label for="interval">Zeitraum:</label>
        <select name="interval" id="interval">
            <option value="M1">1 Monat</option>
            <option value="M3">3 Monate</option>
            <option value="M6">6 Monate</option>
            <option value="Y1" selected="selected">1 Jahr</option>
            <option value="Y3">3 Jahre</option>
            <option value="Y5">5 Jahre</option>
        </select> 
    </fieldset>
    <span class="button button-purple button-tiny"> 
        <input type="submit" value="Anzeigen"> 
    </span>
</form> 

I can complete simple search forms just fine. However, with this one I tried everything and it still doesn't work. I tried to use the clickdata parameter, but it needs a 'name' attribute of the button, which isn't given here.

Here is the code that I tried using so far:

def history_popup(self, response):
    yield FormRequest.from_response(response,
          formxpath="//input[@id='dateStart']",
          formdata={"dateStart":"09.08.2013"},
          callback=self.history_miner) 

I know this is incomplete, but I hope I am on the right track here. My question: How can I make it click the button as well as select one of the options from the drop-down menu?

Any kind of help is much appreciated! Thanks!

Nicolás Alejandro Ramírez Quiros

unread,
Aug 23, 2014, 11:29:07 AM8/23/14
to scrapy...@googlegroups.com
Just use the option value you want with the name of select as key in formdata, for example {'interval': 'Y1'}.
Reply all
Reply to author
Forward
0 new messages