adding main file
This commit is contained in:
parent
432dfc82ad
commit
6576ae6932
1 changed files with 41 additions and 0 deletions
41
main.py
Normal file
41
main.py
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
from sys import argv
|
||||||
|
from os import environ
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from cloudscraper import CloudScraper
|
||||||
|
|
||||||
|
class Scraper:
|
||||||
|
def __init__(self, pseudo, password, app):
|
||||||
|
self.url = "https://forum.mobilism.org"
|
||||||
|
self.requested_app = app
|
||||||
|
self.loginData = {
|
||||||
|
"username": pseudo,
|
||||||
|
"password": password,
|
||||||
|
"login": "Login",
|
||||||
|
"redirect": "./ucp.php?mode=login",
|
||||||
|
"redirect": "index.php"
|
||||||
|
}
|
||||||
|
|
||||||
|
def connect(self):
|
||||||
|
with CloudScraper(browser = {"browser": "chrome", "platform": "windows"}, debug = True) as session:
|
||||||
|
reponse = session.get(f"{self.url}/ucp.php?mode=login")
|
||||||
|
if reponse.status_code != 200:
|
||||||
|
raise ConnectionRefusedError(f"[{reponse.status_code}]")
|
||||||
|
self.loginData["sid"] = reponse.cookies.get_dict()["ppcw_29d3s_sid"]
|
||||||
|
reponse = session.post(f"{self.url}/ucp.php?mode=login", data = self.loginData)
|
||||||
|
if reponse.status_code != 200:
|
||||||
|
raise ConnectionRefusedError(f"[{reponse.status_code}]")
|
||||||
|
print(self.loginData)
|
||||||
|
print(reponse.status_code, reponse.url)
|
||||||
|
with open("temp.html", "w") as f:
|
||||||
|
f.writelines(reponse.text)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
argv = argv[1:]
|
||||||
|
if len(argv) == 3:
|
||||||
|
print(Scraper(*argv).connect())
|
||||||
|
else:
|
||||||
|
#try:
|
||||||
|
load_dotenv()
|
||||||
|
print(Scraper(environ["PSEUDO_MOBILISM"], environ["PASSWORD_MOBILISM"], environ["APP_MOBILISM"]).connect())
|
||||||
|
#except:
|
||||||
|
# print('Please fill in the username and password (with ") by args or with .env file.')
|
Reference in a new issue