tags:

views:

342

answers:

2

In Python, I'm trying to read the values on http://utahcritseries.com/RawResults.aspx. How can I read years other than the default of 2002?

So far, using mechanize, I've been able to reference the SELECT and list all of its available options/values but am unsure how to change its value and resubmit the form.

I'm sure this is a common issue and is frequently asked, but I'm not sure what I should even be searching for.

A: 

With problems relating to AJAX-loading of pages, use Firebug!

Install and open Firebug (it's a Firefox plugin), go to the Net page, and make sure "All" is selected. Open the URL and change the select box, and see what is sent to the server, and what is received.

It seems the catchily-named field ctl00$ContentPlaceHolder1$ddlSeries is what is responsible.. Does the following work..?

import urllib

postdata = {'ctl00$ContentPlaceHolder1$ddlSeries': 9}

src = urllib.urlopen(
    "http://utahcritseries.com/RawResults.aspx",
    data = urllib.urlencode(postdata)
).read()

print src
dbr
No, that doesn't work-when I print src, I still see values from 2002. I tried something similar(albeit MANY more lines ;) - I'm just a rookie )
Neil Kodner
+1  A: 

So how about this:

from mechanize import Browser
year="2005"

br=Browser()
br.open("http://utahcritseries.com/RawResults.aspx")
br.select_form(name="aspnetForm")
control=br.form.find_control("ctl00$ContentPlaceHolder1$ddlSeries")
control.set_value_by_label((year,))
response2=br.submit()

print response2.read()
flight