I am trying to enter the site http://www.sj.se/travel/booksearchlocation.form?mode=normal&l=sv using Mechanize Python using the following code:
import mechanize
import cookielib
# Browser
br = mechanize.Browser()
# Cookie Jar
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
# Browser options
br.set_handle_equiv(True)
#br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
# Follows refresh 0 but not hangs on refresh > 0
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
# Open site
r = br.open("http://www.sj.se/travel/booksearchlocation.form?mode=normal&l=sv")
Selecting the form using
br.select_form(name='travelQuery')
Works fine but when selecting in input field with name: "travelQuery.departureLocationName"
br["travelQuery.departureLocationName"] = "Uppsala C"
I get the following error:
Traceback (most recent call last):
File "/home/joel/workspace/test/test/__init__.py", line 53, in <module>
br["travelQuery.departureLocationName"] = "Uppsala C"
File "/usr/local/lib/python2.7/dist-packages/mechanize/_form.py", line 2780, in __setitem__
control = self.find_control(name)
File "/usr/local/lib/python2.7/dist-packages/mechanize/_form.py", line 3101, in find_control
return self._find_control(name, type, kind, id, label, predicate, nr)
File "/usr/local/lib/python2.7/dist-packages/mechanize/_form.py", line 3185, in _find_control
raise ControlNotFoundError("no control matching "+description)
mechanize._form.ControlNotFoundError: no control matching name 'travelQuery.departureLocationName'
I am certain that this input field exists, because I can see it when viewing the source code of the site. When printing form i get the following result:
<travelQuery POST http://www.sj.se/travel/booksearchlocation.form;jsessionid=ED17C7B9906560F4DFAC8FD3DBA6E258.p1?mode=normal&l=sv application/x-www-form-urlencoded
<HiddenControl(method=) (readonly)>
<HiddenControl(mode=) (readonly)>
<IgnoreControl(<None>=<None>)>
<IgnoreControl(<None>=<None>)>>
Why can't I select the input fields?