3

I am trying to login into the website http://ogame.us using python to access the data. After looking around the web to find out how to attempt to do this, I settled on using the mechanize module. I think I have the general gist of the code down, but when I submit the html form nothing happens. Here's the code:

import sys,os
import mechanize, urllib
import cookielib
from BeautifulSoup import BeautifulSoup,BeautifulStoneSoup,Tag
import datetime, time, socket
import re,sys,os,mechanize,urllib,time,  urllib2


br = mechanize.Browser()
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)

# Browser options
br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)

# Follows refresh 0 but not hangs on refresh > 0
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

# User-Agent (this is cheating, ok?)
br.addheaders = [('User-agent', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US;    rv:1.9.0.6')]
br.open('http://ogame.us')

br.select_form(name = 'loginForm' )

br['login'] = 'stackexample'
br['pass'] = 'examplepassword'
br['uni_url'] = ['uni103.ogame.us']

br.submit()

print br.geturl()

The response from geturl() is the same url that I was at before. Anyone know what is going on?

3 Answers 3

2

Try this:

    data = br.submit()
    html=data.read()
Sign up to request clarification or add additional context in comments.

1 Comment

It didn't seem to do the trick. When I printed html I got the html from the login screen and geturl() still returned the login url.
1

Maybe select the button directly?

response = br.submit(type="submit", id="loginSubmit")

2 Comments

Again, nothing. This code did work on other websites, too, which puzzles me.
have you tried putting braces around login and password? br['login'] = ['stackexample'] br['pass'] = ['examplepassword'] Maybe you need to also simulate pressing on the login button that makes the login menu pop up, although I doubt thats it.
0

There is a third field (uni) that I was not completing. Everything else was correct.

In the future, with Google Chrome (and probably other browsers) you can view the actual requests sent to the browser by opening Chrome Developer Tools and looking under network. This saves quite a bit of time.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.