I am trying to get machine-parsable bus schedule data by submitting a form with mechanize.
However, I am stymied by the mechanize syntax for setting
import mechanize
br = mechanize.Browser()
br.open("http://www.planibus.sto.ca/HastinfoWeb/StartTimetableForm.aspx")
br.select_form(name="TimetableQueryForm")
br["RouteDirectionDynamicComboBox$ComboBox_Input"] = "10 OTTAWA" # works fine, it's a TextControl
br["DatePicker$DaysDropDownList"] = ["3"] # This is a SelectControl
### mechanize._form.ItemNotFoundError: insufficient items with name '3'
mechanize._form.ItemNotFoundError: insufficient items with name '3' looks like it needs a list, but when I enter more than one item in the list (which makes little sense, given that this is a date picker) I get:
mechanize._form.ItemCountError: single selection list, must set sequence of length 0 or 1
I thought that my original ["3"] was a sequence of length 1?
Thanks for your attention. I’m probably missing something obvious…
Edit: note that the ‘3’ above is just one value, and the web site allows values for the next two weeks in its UI, so depending on when you see this, the list of allowable values will change. Just substitute the ‘3’ with one of the allowable values… Still doesn’t work for me…
3 isn’t one of the available select options, the options I see are
So try
br["DatePicker$DaysDropDownList"] = ["4"]and your code should work.Edit: I’ve actually tried looking at the page in question with mechanize, try this
There aren’t any options, I imagine that javascript is used to populate them after the page has loaded. Unfortunatly mechanize doesn’t support javascript, try using Selenium Webdriver to scrape the data you need.