AlcasarAuto/main.py

43 lines
1.8 KiB
Python

import json
import requests
from bs4 import BeautifulSoup
username = "username"
password = "password"
ses = requests.Session()
ses.headers = {"Origin": "https://alcasar-0320002d.smile-education.fr", "Accept-Encoding": "gzip, deflate, br",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
"Sec-Fetch-Mode": "navigate", "Connection": "keep-alive",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0",
"Content-Type": "application/x-www-form-urlencoded", "Sec-Fetch-Site": "same-origin",
"Sec-Fetch-Dest": "document", "Accept-Language": "fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3",
"Sec-Fetch-User": "?1"}
connection_page = ses.get("http://detectportal.firefox.com/canonical.html")
soup = BeautifulSoup(connection_page.text, features="html.parser")
input_challenge = soup.find("input", {"name": "challenge"})
challenge = input_challenge["value"]
data = f"challenge={challenge}&userurl=http%3A%2F%2Fdetectportal.firefox.com%2Fcanonical.html&username={username}&password={password}&button=Authentification"
resp = ses.post("https://alcasar-0320002d.smile-education.fr/intercept.php",
data=data,
allow_redirects=False, headers={"Origin": "https://alcasar-0320002d.smile-education.fr",
"Referer": connection_page.url})
print(resp.text)
redirect = resp.headers["Location"]
print(redirect)
ses.get(redirect)
statut = json.loads(
ses.get("http://alcasar-0320002d.smile-education.fr:3990/json/status?callback=chilliJSON.reply").text[17:-1])
if statut["clientState"]:
print("Successfully connected!")
else:
print("An error occured")