Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CredentialsFrame(customtkinter.CTkFrame):
- username = ""
- password = ""
- def __init__(self, master):
- super().__init__(master)
- self.inputUsername = StringVar()
- self.inputUsername.set(CredentialsFrame.username.strip())
- self.inputPassword = StringVar()
- self.inputPassword.set(CredentialsFrame.password.strip())
- # ENTRY
- self.entryUsername = customtkinter.CTkEntry(self, width=100, textvariable=self.inputUsername)
- self.entryUsername.grid(column=1, row=9, sticky="EW")
- self.entryPassword = customtkinter.CTkEntry(self, width=100, show="*", textvariable=self.inputPassword)
- self.entryPassword.grid(column=1, row=10, sticky="EW")
- # LABELS
- customtkinter.CTkLabel(self, text="Email: ").grid(column=0, row=9, sticky="EW")
- customtkinter.CTkLabel(self, text="Password: ").grid(column=0, row=10, sticky="EW")
- # BUTTON
- self.buttonLogin = customtkinter.CTkButton(self, text="Login", command=self.login)
- self.buttonLogin.grid(column=1, row=11, sticky="EW")
- def login(self):
- try:
- CredentialsFrame.username = self.entryUsername.get()
- CredentialsFrame.password = self.entryPassword.get()
- # Logon using the logon information provided and store that under our session
- browser = mechanize.Browser()
- browser.addheaders = [('User-agent', 'Tu się przedstawiam stronie według wymagań admina')]
- browser.open("https://strona-internetowa.net")
- browser.select_form(id="Form1")
- browser.form["textLogin"] = CredentialsFrame.username
- browser.form["textPassword"] = CredentialsFrame.password
- browser.submit()
- CTkMessagebox(title="Info", message="Logged in successfully!",
- icon="check", option_1="Thanks")
- except Exception:
- CTkMessagebox(title="Error", message="Invalid login/password")
- return browser
- class TestingFrame(customtkinter.CTkFrame):
- def __init__(self, master, title):
- super().__init__(master)
- self.grid_columnconfigure(0, weight=1)
- self.title = title
- # nieistotne elementy budujące zakładkę w customtkinterze
- # Button fill data
- self.calculate_button = customtkinter.CTkButton(self, text="Fill Data", command=self.fillData)
- self.calculate_button.grid(row=8, column=0, columnspan=2, sticky="ew")
- def fillData(self):
- #tu się odwołuję do browser zwróconego wyżej już po logowaniu
- try:
- CredentialsFrame.browser.follow_link(url_regex=re.compile("Podstrona"))
- tree = html.fromstring(CredentialsFrame.browser.response().get_data())
- CredentialsFrame.browser.back()
Advertisement
Add Comment
Please, Sign In to add comment