Mar-25-2022, 05:40 PM
Hi all, i'm going to try to explain this as accurately as i can.
My end goal is to successfully code a web scraper with Selenium with user inputs via Tkinter and successfully search for an address in the search bar on thisWebsite where address is searched . I can successfully 'hardcode' an address which is forwarded into here and data is scraped, im struggling to get Tkinter values to be searched. Is there a 'standard' way to do this? I cannot find any information regarding this online.
When the code is running, the user can input the address into the Tkinter Gui, by pressing search, selenium runs and opens the webpage, however crashes shortly because its automatically pressing the search button whilst no user input is being forwarded.
Here is my code so far:
What im using for the user input in this case is the 'Userarg'.
Thanks for any help :)
P.S if theres anything i can change next time feel free to comment
My end goal is to successfully code a web scraper with Selenium with user inputs via Tkinter and successfully search for an address in the search bar on thisWebsite where address is searched . I can successfully 'hardcode' an address which is forwarded into here and data is scraped, im struggling to get Tkinter values to be searched. Is there a 'standard' way to do this? I cannot find any information regarding this online.
When the code is running, the user can input the address into the Tkinter Gui, by pressing search, selenium runs and opens the webpage, however crashes shortly because its automatically pressing the search button whilst no user input is being forwarded.
Here is my code so far:
import tkinter as tk import time from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from threading import Thread from multiprocessing import Process window = tk.Tk() # Opening Webpage #PATH = "C:\Program Files (x86)\chromedriver.exe" #driver = webdriver.Chrome(PATH) #driver.get("https://creeper.banano.cc/") #Defining functions needed def Sel(USER): PATH = "C:\Program Files (x86)\chromedriver.exe" # setting the path(where to find the file) driver = webdriver.Chrome(PATH) # browser used is chrome -> path to it where the exe. is defined by PATH #8F0604B65C973F931D6E909ACD819D276AB1DF4C1FF161E754D509075C4BD2EC driver.get("https://creeper.banano.cc/") #USER = input('Enter the user transaction:') print(USER) search = driver.find_element(By.CSS_SELECTOR,".ValidatedSearch.form-control.form-control-lg") #searching for the main address search bar search.send_keys(USER) link = driver.find_element(By.CSS_SELECTOR,".btn.btn-nano-primary.btn-lg") # defining the link by searching for the CSS_SELECTOR time.sleep(5) link.click() # automatically clicking the link time.sleep(5) Data = driver.find_element(By.XPATH,"//*[@id='Content']/div/div[2]/div/div/pre/code").text print(Data) def run_app(Userarg): print(Userarg) b = Process(target=Sel, args=([Userarg.get()])) b.start() def close_app(): window.destroy() def Gui(): window = tk.Tk() window.title("Banano Transaction Searcher") frame_header = tk.Frame(master = window, borderwidth=8, pady=8) center_frame = tk.Frame(window, borderwidth=8, pady=8) bottom_frame = tk.Frame(window, borderwidth=8, pady=8) frame_header.grid(row=0, column=0) center_frame.grid(row=1, column=0) bottom_frame.grid(row=2, column=0) header = tk.Label(frame_header, text = "Banano Transaction Searcher", bg='grey', fg='black', height='2', width='40', font=("Helvetica 16")) header.grid(row=0, column=0) frame_main_1 = tk.Frame(center_frame, borderwidth=2, relief='sunken') frame_main_2 = tk.Frame(center_frame, borderwidth=2, relief='sunken') frame_main_1.pack(fill='x', pady=2) frame_main_2.pack(fill='x', pady=2) Ban_Add = tk.Label(frame_main_1, text = "Banano Address: ") TXN_AMT = tk.Label(frame_main_2, text = "Transaction Ammount: ") Ban_Add1 = tk.StringVar() #lambda Ban_Add : Process(target=Sel, args=([Ban_Add1]).start() print('Started Thread') Ban_Add_User = tk.Entry(frame_main_1, textvariable = Ban_Add1, width=32) frame_main_1.pack(fill='x', pady=2) frame_main_2.pack(fill='x', pady=2) Ban_Add.pack(side="left") Ban_Add_User.pack(side='left', pady=1) TXN_AMT.pack(side="left") button_run = tk.Button(bottom_frame, text="Search", command= lambda : run_app(Ban_Add1), bg='green', fg='white', relief='raised', width=10, font=('Helvetica 10 bold')) button_run.grid(column=0, row=0, sticky='w', padx=100, pady=2) button_close = tk.Button(bottom_frame, text="Stop", command=close_app, bg='red', fg='white', relief='raised', width=10, font=('Helvetica 10 bold')) button_close.grid(column=1, row=0, sticky='e', padx=100, pady=2) window.mainloop() if __name__ == "__main__": Gui()The user address is : 8F0604B65C973F931D6E909ACD819D276AB1DF4C1FF161E754D509075C4BD2EC
What im using for the user input in this case is the 'Userarg'.
Thanks for any help :)
P.S if theres anything i can change next time feel free to comment