I am trying to program an automation tool for an online game called travian. I want to login using a python browser object (created by using the mechanise library). Once I have logged in I want to open a real webbrowser (ie. chrome).
#here I create a mechanize browser object
b = mechanize.Browser()
#usually to login to the game you go to this
# site and put in your login and password and press submit
server = 'http://ts4.travian.com/?lang=en'
#I am trying here to use a browser object to submit the form,
#maybe there is a mistake here
b.open(server)
b.select_form("login")
b.form["name"] = 'myAccount'
b.form["password"] = 'myPassword'
b.submit()
#once mechanise has submitted the form I want to
#open the page in chrome that would usually be
#opened if I were to submit it by hand
gamePage = ("http://ts4.travian.com/dorf1.php")
webbrowser.open_new_tab(gamePage)
When I run this code it opens the login page, that is, the code that logs in to the game does not seem to have worked.
This was an old question of mine. The the easiest way to do what I was trying to achieve is to use a class called Selenium.