I have been using this guide to help me: http://www.pythonforbeginners.com/cheatsheet/python-mechanize-cheat-sheet/
I want to log into Stack Overflow and print out my login response using Mechanize in Python. I have been troubleshooting to find a form name to select and enter my information into, but am currently getting an error "ValueError: at least one argument must be supplied to specify control" because I am trying to print out all forms and controls to help me figure out what I need to choose from.
import mechanize
#make browser object
browser = mechanize.Browser()
#open stack login page
browser.open("http://stackoverflow.com/users/login#login-in")
#print all the forms on the page
print("\n Printing all forms on page...\n")
for form in browser.forms():
print("Form Name:", form.name)
print form
print("\n Done printing forms...\n")
#printing the controls of each form
browser.form=list(browser.forms())[0]
print("\n Printing controls of form 0 \n")
for control in browser.form.controls:
print control
print "type=%s, name=%s, value=%s" % (control.type, control.name, browser[control.name])
browser.form=list(browser.forms())[1]
print("\n Printing controls of form 1 \n")
for control in browser.form.controls:
print control
print "type=%s, name=%s, value=%s" % (control.type, control.name, browser[control.name])
browser.form=list(browser.forms())[2]
print("\n Printing controls of form 2 \n")
for control in browser.form.controls:
print control
print "type=%s, name=%s, value=%s" % (control.type, control.name, browser[control.name])
print("\n Done printing all controls \n")
It looks like there are 3 forms on the page, but they do not contain the email and password inputs I am looking for to login. What am I doing wrong?