from sys import argv from requests import Session from bs4 import BeautifulSoup from requests.models import Response class Universite: def __init__(self, url, pseudo, motDePasse): self.url = url self.loginData = { "username": pseudo, "password": motDePasse, "_eventId": "submit", "submit": "SE CONNECTER" } def mySoup(self, page): return BeautifulSoup(page.content, "html.parser") def recuperationNotes(self): with Session() as session: # login reponse = session.get(self.url) soup = self.mySoup(reponse) self.loginData["lt"] = soup.find("input", attrs = {"name": "lt"})["value"] self.loginData["execution"] = soup.find("input", attrs = {"name": "execution"})["value"] reponse = session.post(self.url, data = self.loginData) # page des résultats intermédiaire soup = self.mySoup(reponse) url = soup.find("a", attrs = {"id": "service-407"})["href"] reponse = session.get(url, allow_redirects = False) url = reponse.headers["Location"] reponse = session.get(url) # page choix de l'année -- soup = self.mySoup(reponse) notes = { "formMenu_SUBMIT": "1", "formMenu:_idcl": "formMenu:linknotes1", "formMenu:_link_hidden_": "", "javax.faces.ViewState": soup.find("input", attrs = {"name": "javax.faces.ViewState"})["value"] } reponse = session.post(url, data = notes, allow_redirects = False) print(reponse.status_code) # url = reponse.headers["Location"] # reponse = session.get(url) # print(reponse.text) """ # page des notes dernierFormulaire = { "_id142Pluto_146_ctf2_168897__SUBMIT": "1", "_id142Pluto_146_ctf2_168897_:_idcl": "_id142Pluto_146_ctf2_168897_:tabledip:0:_id148Pluto_146_ctf2_168897_", "_id142Pluto_146_ctf2_168897_:_link_hidden_": "", "row": "0", "javax.faces.ViewState": notes["javax.faces.ViewState"] } reponse = session.post(url, data = notes, allow_redirects = False) url = reponse.headers["Location"] reponse = session.get(url) # récupération tableau soup = self.mySoup(reponse) return soup.find("table", attrs = {"id": "_id109Pluto_146_ctf2_168897_:tableel"}) """ if __name__ == "__main__": argv = argv[1:] if len(argv) == 3: print(Universite(*argv).recuperationNotes()) else: print("Merci de renseigner l'URL, le pseudo et le mot de passe (avec des \").")