The driver is set to be headless and there is a loop that iterates through URLs and gets some action done. The idea is to run this in the background without disrupting workflow but the terminal keeps popping up with this code. If I would execute the program in the terminal, it is fine because all the output is sent in one place but there is a need for a GUI. I tried moving the driver so that it would be share across the URLs fetched but there is an ID error and appears that a new driver instance needs to be created. There is multiprocessing to avoid Tkinter from freezing by running multiple processes. Pyinstaller was also used to execute the program. Using the command "pyinstaller -w -F --onefile TMO_Scrub.pyw" but still not luck. Seems its the console from the chrome driver.
Following is the code:
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from tkinter import *
import multiprocessing as mp
class Scrub:
def __init__(self, master):
mp.freeze_support()
self.master = master
self.submit_btn = Button(
self.master, text='Submit', command=self.submit)
self.submit_btn.pack()
def submit(self):
self.t1 = mp.Process(target=execute)
self.t1.daemon = True
self.t1.start()
def execute():
try:
urls = ['https://www.google.com/', 'https://www.youtube.com/',
'https://www.instagram.com/', 'https://www.facebook.com/', 'https://www.cnn.com/']
for url in urls:
scrape_page(url)
except NameError:
print('There was an error...')
def scrape_page(url):
opts = Options()
opts.add_argument("headless")
chrome_driver = os.getcwd() + "\chromedriver.exe"
driver = webdriver.Chrome(options=opts, executable_path=chrome_driver)
driver.get(url)
driver.quit()
if __name__ == '__main__':
root = Tk()
gui = Scrub(root)
root.mainloop()