Search code examples
pythonlistscreen-scrapingmechanizeasterisk

python mechanize problem with selectcontrol


basically one of the select controls has a few "options" in which to choose from

if i use:

for t in br.forms():
        print t

the output i get is

`SelectControl(ctl00$cph2$ddlSchool=[*2])
 SelectControl(ctl00$cph2$ddlMarkingPeriod=[*1, 2, 3, 4])
 SelectControl(ctl00$cph2$ddlCourseSection=[*1120:01:1, 1515:01:1, 2445:01:1, 3723:02:1, 4140:03:1, 5100:08:1, 1:01:1, 9970:07:1, 9913:01:1])>
 SubmitControl(ctl00$cph2$btnExecuteReport=Execute) (readonly)`

notice the asterisks

now, what i want is to store the list under "ctl00$cph2$ddlCourseSection" in my program but if i try and store it and then print it:

save = br.form['ctl00$cph2$ddlCourseSection'] 
print save

the output i get is:

['1120:01:1']

instead of:

['1120:01:1', '1515:01:1', '2445:01:1', '3723:02:1', '4140:03:1', '5100:08:1', '1:01:1', '9970:07:1', '9913:01:1']

so how would i be able to save all of the elements of the list rather than just the element with the asterisk next to it?


Solution

  • By doing this you only get the default value.

    save = br.form['ctl00$cph2$ddlCourseSection'] 
    print save
    

    To get all values you have to use

    save = br.form.possible_items('ctl00$cph2$ddlCourseSection')
    print save
    

    i didn't test it but i think it will work.