Created
August 3, 2011 22:23
-
-
Save martinth/1123978 to your computer and use it in GitHub Desktop.
mode.de login script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import cookielib | |
from urllib2 import HTTPCookieProcessor, build_opener | |
from urllib import urlencode | |
from BeautifulSoup import BeautifulSoup | |
# the login data | |
login_data = { | |
'login_username': u'USERNAME', | |
'login_password': u'PASSWORD', | |
'login_lifetime': u'31536000', | |
} | |
# we need a cookie jar to hold the cookies and a opener that uses this jar | |
jar = cookielib.CookieJar() | |
cookie_handler = HTTPCookieProcessor(jar) | |
opener = build_opener(cookie_handler) | |
# post data must be encoded before submitting (as iso-8859-15) | |
login_data_encoded = dict([k, v.encode('iso-8859-15')] for k, v in login_data.items()) | |
# submit login data | |
res = opener.open('http://login.mods.de/', urlencode(login_data_encoded)) | |
# search for the iframe that has the SSO.php script for forum.mods.de... | |
soup = BeautifulSoup(res.read()) | |
for iframe in soup.findAll('iframe'): | |
sso = iframe['src'] | |
if 'forum.mods.de' in sso: | |
# ... and make a request to this page | |
opener.open(sso) | |
# now you are logged in | |
res = opener.open('http://forum.mods.de/bb/index.php') | |
print res.read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment