Skip to content

Instantly share code, notes, and snippets.

What would you like to do? login script
# -*- 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 ='', urlencode(login_data_encoded))
# search for the iframe that has the SSO.php script for
soup = BeautifulSoup(
for iframe in soup.findAll('iframe'):
sso = iframe['src']
if '' in sso:
# ... and make a request to this page
# now you are logged in
res ='')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment