Guest User

Untitled

a guest
Apr 18th, 2024
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.93 KB | Software | 0 0
  1. class CredentialsFrame(customtkinter.CTkFrame):
  2.     username = ""
  3.     password = ""
  4.     def __init__(self, master):
  5.         super().__init__(master)
  6.         self.inputUsername = StringVar()
  7.         self.inputUsername.set(CredentialsFrame.username.strip())
  8.         self.inputPassword = StringVar()
  9.         self.inputPassword.set(CredentialsFrame.password.strip())
  10.         # ENTRY
  11.         self.entryUsername = customtkinter.CTkEntry(self, width=100, textvariable=self.inputUsername)
  12.         self.entryUsername.grid(column=1, row=9, sticky="EW")
  13.         self.entryPassword = customtkinter.CTkEntry(self, width=100, show="*", textvariable=self.inputPassword)
  14.         self.entryPassword.grid(column=1, row=10, sticky="EW")
  15.         # LABELS
  16.         customtkinter.CTkLabel(self, text="Email: ").grid(column=0, row=9, sticky="EW")
  17.         customtkinter.CTkLabel(self, text="Password: ").grid(column=0, row=10, sticky="EW")
  18.         # BUTTON
  19.         self.buttonLogin = customtkinter.CTkButton(self, text="Login", command=self.login)
  20.         self.buttonLogin.grid(column=1, row=11, sticky="EW")
  21.    
  22.     def login(self):
  23.             try:
  24.                 CredentialsFrame.username = self.entryUsername.get()
  25.                 CredentialsFrame.password = self.entryPassword.get()
  26.  
  27.                 # Logon using the logon information provided and store that under our session
  28.                 browser = mechanize.Browser()
  29.                
  30.                 browser.addheaders = [('User-agent', 'Tu się przedstawiam stronie według wymagań admina')]
  31.                 browser.open("https://strona-internetowa.net")
  32.                 browser.select_form(id="Form1")
  33.                 browser.form["textLogin"] = CredentialsFrame.username
  34.                 browser.form["textPassword"] = CredentialsFrame.password
  35.                 browser.submit()
  36.                
  37.                
  38.                 CTkMessagebox(title="Info", message="Logged in successfully!",
  39.                   icon="check", option_1="Thanks")        
  40.             except Exception:
  41.                 CTkMessagebox(title="Error", message="Invalid login/password")
  42.             return browser
  43.        
  44. class TestingFrame(customtkinter.CTkFrame):
  45.     def __init__(self, master, title):
  46.         super().__init__(master)
  47.  
  48.         self.grid_columnconfigure(0, weight=1)
  49.         self.title = title
  50.  
  51.         # nieistotne elementy budujące zakładkę w customtkinterze
  52.        
  53.         # Button fill data
  54.         self.calculate_button = customtkinter.CTkButton(self, text="Fill Data", command=self.fillData)
  55.         self.calculate_button.grid(row=8, column=0, columnspan=2, sticky="ew")
  56.  
  57.     def fillData(self):
  58.         #tu się odwołuję do browser zwróconego wyżej już po logowaniu
  59.         try:
  60.             CredentialsFrame.browser.follow_link(url_regex=re.compile("Podstrona"))
  61.             tree = html.fromstring(CredentialsFrame.browser.response().get_data())
  62.             CredentialsFrame.browser.back()
  63.  
Advertisement
Add Comment
Please, Sign In to add comment