Python selecting a value in a combo box and HTTP POST

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.


Asked by: Alberta653 | Posted: 06-12-2021






Answer 1

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()

Answered by: Arthur430 | Posted: 07-01-2022



Answer 2

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

Answered by: Grace862 | Posted: 07-01-2022



Similar questions

python - Writing a Domain Specific Language for selecting rows from a table

I'm writing a server that I expect to be run by many different people, not all of whom I will have direct contact with. The servers will communicate with each other in a cluster. Part of the server's functionality involves selecting a small subset of rows from a potentially very large table. The exact choice of what rows are selected will need some tuning, and it's important that it's possible for the person running the cl...


python - Selecting related objects in django

I have following problem: My application have 2 models: 1) class ActiveList(models.Model): user = models.ForeignKey(User, unique=True) updatedOn = models.DateTimeField(auto_now=True) def __unicode__(self): return self.user.username ''' GameClaim class, to store game requests. ''' class GameClaim(models.Model): me = models.ForeignKey(ActiveList, related_name='gameclai...


python - Selecting rows from a NumPy ndarray

I want to select only certain rows from a NumPy array based on the value in the second column. For example, this test array has integers from 1 to 10 in the second column. >>> test = numpy.array([numpy.arange(100), numpy.random.randint(1, 11, 100)]).transpose() >>> test[:10, :] array([[ 0, 6], [ 1, 7], [ 2, 1...


python - Selecting indices for a 2d array in numpy

This works quite well in 1 dimension: # This will sort bar by the order of the values in foo (Pdb) bar = np.array([1,2,3]) (Pdb) foo = np.array([5,4,6]) (Pdb) bar[np.argsort(foo)] array([2, 1, 3]) But how do I do that in two dimensions? Argsort works nicely, but the select no longer works: (Pdb) foo = np.array([[5,4,6], [9,8,7]]) (Pdb) bar = np.array([[1,2,3], [1,2,3]]) (P...


python - Selecting specific column in each row from array

I am trying to select specific column elements for each row of a numpy array. For example, in the following example: In [1]: a = np.random.random((3,2)) Out[1]: array([[ 0.75670668, 0.1283942 ], [ 0.51326555, 0.59378083], [ 0.03219789, 0.53612603]]) I would like to select the first element of the first row, the second element of the second row, and the first element of th...


python - Randomly selecting lines from files

I have bunch of files and very file has a header of 5 lines. In the rest of the file, pair of line form an entry. I need to randomly select entry from these files. How can i select random files and random entry(pair of line, excluding header) ?


python - Selecting Widgets

In Tkinter I'm trying to make it so when a command is run a widget is automatically selected, so that a one may bind events to the newly selected widget. Basically I want it so when I press a button a text widget appears. When it appears normally one would have to click the text widget to facilitate the running of events bound to the text widget. I want that behavior to automatically happen when the user clicks th...


python - Django - Selecting related set : how many times does it hit the database?

I took this sample code here : Django ORM: Selecting related set polls = Poll.objects.filter(category='foo') choices = Choice.objects.filter(poll__in=polls) My question is very simple : do you hit twice the database when you finally use the queryset choices ?


python - Selecting and printing specific rows of text file

I have a very large (~8 gb) text file that has very long lines. I would like to pull out lines in selected ranges of this file and put them in another text file. In fact my question is very similar to this and this but I keep gettin...


mysql - Selecting a Python Web Framework

This may seem like a subjective question. But it is not (that's not the idea, at least). I'm developing an Advertising software (like AdWords, AdBrite, etc) and i've decide to use Python. And would like to use one of those well known web frameworks (Django, Cherrypy, pylons, etc). The question is: Given that it will have just a few Models (seven or eight), which has the best cache support? and What ...






Still can't find your answer? Check out these communities...



PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python



top