add comments

This commit is contained in:
Mylloon 2021-08-23 12:30:10 +02:00
parent 6e1b143cb6
commit c6a797c7bb

13
main.py
View file

@ -20,19 +20,22 @@ class Scraper:
return f"\Error: [{code}]{' ' if len(message) > 0 else ''}{message}" return f"\Error: [{code}]{' ' if len(message) > 0 else ''}{message}"
def connect(self): def connect(self):
session = create_scraper(browser = {"browser": "chrome", "platform": "windows"}) session = create_scraper(browser = {"browser": "chrome", "platform": "windows"}) # connect with cloudflare bypasser with a chrome browser on windows
if self.debug: print("Retrieval of the login cookie...", end = " ") if self.debug: print("Retrieval of the login cookie...", end = " ")
reponse = session.get(f"{self.url}/ucp.php?mode=login") reponse = session.get(f"{self.url}/ucp.php?mode=login") # get login page to get "sid"
if reponse.status_code != 200: if reponse.status_code != 200:
raise ConnectionRefusedError(self.errorFormat(reponse.status_code)) raise ConnectionRefusedError(self.errorFormat(reponse.status_code))
self.loginData["sid"] = reponse.cookies.get_dict()["ppcw_29d3s_sid"] self.loginData["sid"] = reponse.cookies.get_dict()["ppcw_29d3s_sid"] # register "sid"
if self.debug: print("Cookie retrieval done, connection attempt...", end = " ") if self.debug: print("Cookie retrieval done, connection attempt...", end = " ")
reponse = session.post(f"{self.url}/ucp.php?mode=login", data = self.loginData) reponse = session.post(f"{self.url}/ucp.php?mode=login", data = self.loginData) # connect to the forum using credentials
if reponse.status_code != 200: if reponse.status_code != 200:
raise ConnectionRefusedError(self.errorFormat(reponse.status_code)) raise ConnectionRefusedError(self.errorFormat(reponse.status_code))
if self.debug: print("Connection done.") if self.debug: print("Connection done.")
if self.debug: print(reponse.status_code, reponse.url) if self.debug: print(reponse.status_code, reponse.url)
with open("temp.html", "w") as f: with open("temp.html", "w") as f: # debug
f.writelines(reponse.text) f.writelines(reponse.text)
return session return session