我正在尝试编写一个称为travian的在线游戏的自动化工具。 我想使用python浏览器对象(使用mechanise库创建)登录。一旦我登录,我想打开一个真正的浏览器(即。铬)。用Python/Mechanize打开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)
当我运行这段代码将打开登录页面,也就是登录到游戏中的代码似乎没有工作过。