I try to build a bot which automatically scrapes website by making Exe file of python script. For scraping I use python selenium and for user interface I use tkinter.
import tkinter as tk
class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.create_widgets()
def create_widgets(self):
self.hi_there = tk.Button(self)
self.hi_there["text"] = "Hello World\n(click me)"
self.hi_there["command"] = self.say_hi
self.hi_there.pack(side="top")
self.quit = tk.Button(self, text="QUIT", fg="red",
command=self.master.destroy)
self.quit.pack(side="bottom")
def say_hi(self):
chrome_path=r"C:\Users\ANISH JAIN\Documents\PYTHON_PROGRAMME\ABOTS\chromedriver.exe"
chrome_options = Options()
chrome_options.add_argument('--user-data-dir=./User_Data')
chrome_options.add_argument('-headless')
driver = webdriver.Chrome(executable_path=chrome_path, options=chrome_options)
driver.get('https://web.telegram.org/#/login')
sleep(20)
contact_class = 'im_dialog_peer'
contacts_sel = driver.find_elements_by_class_name(contact_class)
contacts = []
for cs in contacts_sel:
contacts.append(cs.text)
print("Hi there!!!")
print(contacts)
root = tk.Tk()
root.geometry('350x450+700+200')
app = Application(master=root)
app.mainloop()
when
chrome_options.add_argument('-headless')
this code is commented everything works fine but when it is uncommented code gives
this error:
selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist