I am using Python Mechanize to open a website, fill out a form, and submit that form. It's actually pretty simple. It works until I come across radio buttons and "select" input boxes.
br.open(url)
br.select_form(name="postmsg")
br.form['subject'] = "Is this good for the holidays? "
br.form['message'] = "I'm new to technology."
br.form['E'] = '0'
br.submit()
br.form['E'] = '0'
File "build/bdist.linux-x86_64/egg/ClientForm.py", line 2897, in __setitem__
File "build/bdist.linux-x86_64/egg/ClientForm.py", line 2092, in __setattr__
File "build/bdist.linux-x86_64/egg/ClientForm.py", line 2100, in _set_value
TypeError: ListControl, must set a sequence
Why am I getting this error? Why can't I set E just like the text boxes? (E is a radio button)
Edit: This is the form, according to Web Developer.
Elements
Index Id Name Type Value Label Size Maximum Length State
0 subject subject text 35
2 message message textarea
3 identity identity select 1
13 action_btn hidden
14 _charset_ hidden
16 r hidden /Stocks_(A_to_Z)/Stocks_G
9 E radio 0
Checked
8 E radio 1
15 .crumb hidden 1n1Yo3MQae3
7 E radio 2
17 bn hidden 25263
6 E radio 3
5 E radio 4
4 E radio 5
12 SubmitCancel SubmitCancel submit Cancel
1 mbpostthreads threads button Check Existing Topics First
11 SubmitPost SubmitPost submit Post Message
10 SubmitPreview SubmitPreview submit Preview Message
18 yIdCoreIdUser hidden annamae41g
Radio buttons and Check-boxes can have different behavior then other elements. It depends on their name and id.
If the items have the same name, try doing this:
br.find_control(name="E").value = ["0"]
Another option is:
form.find_control(name="E", kind="list").value = ["0"]
and finally, this might work:
br["E"] = ["0"]
(I haven't used mechanize in a while so i don't remember exactly).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With