Skip to content

Instantly share code, notes, and snippets.

@Nodraak
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nodraak/b2d4a9a646e89dbea3c1 to your computer and use it in GitHub Desktop.
Save Nodraak/b2d4a9a646e89dbea3c1 to your computer and use it in GitHub Desktop.
ece api
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import bs4
class EceApi:
def __init__(self):
self.url_auth_get = 'https://webauth.ece.fr/cas/login?service='
self.url_auth_post = 'https://webauth.ece.fr/'
def _assert_length(self, item, length=1):
if len(item) != length:
raise IndexError
def get(self, url_action, username, password):
url = self.url_auth_get + url_action
r = requests.get(url, verify=False)
html = r.content
soup = bs4.BeautifulSoup(html)
form = soup.find_all('form')
self._assert_length(form)
form = form[0]
action = soup.find_all('form')
self._assert_length(action)
action = action[0].get('action')
lt = form.find_all('input', attrs={'name': 'lt'})
self._assert_length(lt)
lt = lt[0].get('value')
event = form.find_all('input', attrs={'name': '_eventId'})
self._assert_length(event)
event = event[0].get('value')
data = {
'username': username,
'password': password,
'lt': lt,
'_eventId': event,
}
return requests.post(self.url_auth_post+action, verify=False, data=data)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from eceApi import EceApi
ea = EceApi()
r = ea.get('http://webapps.ece.fr/mes-notes/actuelles/', 'login', 'pass')
print r.status_code
print r.content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment