Question

I have an email client. I check the "checkboxes" of emails that I need do something (move,detele, egg) like this using python mechanize:

br.open(login_url)
br.open(url_1)
br.select_form(nr=0)
for i in range(0, len(br.find_control(type="checkbox").items)):
    if "4" in str(br.find_control(type="checkbox").items[i]):
        br.find_control(type="checkbox").items[i].selected = False
    else:
        br.find_control(type="checkbox").items[i].selected = True
reponseaa = br.submit()
print reponseaa

br.open(url_2)
br.select_form(nr=2)
for i in range(0, len(br.find_control(type="checkbox").items)):
    if "45198" and "4519" in str(br.find_control(type="checkbox").items[i]):
        br.find_control(type="checkbox").items[i].selected = True
    else:
        br.find_control(type="checkbox").items[i].selected = False
br.form['self'] = ["88"]
r1 = br.submit()
print r1

the problem is with the submit button, which is a dropdown menu, that looks like this:

<select name="self">
<option value="0">Select an action</option>
<option value="87">Move</option>
<option value="88">Delete</option>
<option value="89">Mark as Important</option>
</select>
<input type="submit" name="submit" value="Action!">

How I can select Delete and push the submit button? A code example would be great. Thanks.

Was it helpful?

Solution

You should use form from mechanize :

import mechanize

br = mechanize.Browser()
br.open(URL)
br.select_form(nr=0)
br.form['self'] = ["88"]
r = br.submit()

print r.read()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top