now the connection is working
This commit is contained in:
parent
c6a797c7bb
commit
08ddd95461
1 changed files with 7 additions and 5 deletions
12
main.py
12
main.py
|
@ -17,23 +17,24 @@ class Scraper:
|
|||
}
|
||||
|
||||
def errorFormat(self, code: int, message: str = "") -> str:
|
||||
return f"\Error: [{code}]{' ' if len(message) > 0 else ''}{message}"
|
||||
return f"Error: [{code}]{' ' if len(message) > 0 else ''}{message}"
|
||||
|
||||
def connect(self):
|
||||
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 SID...", end = " ")
|
||||
reponse = session.get(f"{self.url}/ucp.php?mode=login") # get login page to get "sid"
|
||||
if reponse.status_code != 200:
|
||||
raise ConnectionRefusedError(self.errorFormat(reponse.status_code))
|
||||
raise ConnectionError(self.errorFormat(reponse.status_code))
|
||||
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("SID retrieval done, connection attempt...", end = " ")
|
||||
reponse = session.post(f"{self.url}/ucp.php?mode=login", data = self.loginData) # connect to the forum using credentials
|
||||
if reponse.status_code != 200:
|
||||
raise ConnectionRefusedError(self.errorFormat(reponse.status_code))
|
||||
|
||||
if self.debug: print("Connection done.")
|
||||
reponse = session.get(f"{self.url}/index.php", cookies = reponse.cookies, params = {"sid": self.loginData["sid"]})
|
||||
if self.debug: print(reponse.status_code, reponse.url)
|
||||
with open("temp.html", "w") as f: # debug
|
||||
f.writelines(reponse.text)
|
||||
|
@ -41,8 +42,9 @@ class Scraper:
|
|||
return session
|
||||
|
||||
def search(self, session):
|
||||
link = "No link for your application was found."
|
||||
if self.debug: print("Going to search page...", end = " ")
|
||||
|
||||
link = "No link for your application was found."
|
||||
return link
|
||||
|
||||
def work(self):
|
||||
|
|
Reference in a new issue