hello how can i stop selenium i close the program but selenium does not stop

Viewed 12

hello how can i stop selenium i close the program but selenium does not stop.

even if i close the program with x at the terminal

[0924/115120.801:INFO:CONSOLE(2)] "JQMIGRATE: Migrate is installed, version 3.3.2", source: https://cdn.termolog.net/wp-content/cache/autoptimize/js/autoptimize_fcfdf5b30583e13a66bd6bb6be00ccc4.js (2) [0924/115120.837:INFO:CONSOLE(52)] "RapidLoad şöÑ 1.0", source: https://cdn.termolog.net/wp-content/cache/autoptimize/js/autoptimize_fcfdf5b30583e13a66bd6bb6be00ccc4.js (52)

these keep popping up can you help me

from termolog import Worker2

class Yukleniyor(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.ui = Ui_SplashScreen()
        self.ui.setupUi(self)


        self.Worker2 = Worker2 ()
        self.Worker2.start()
        self.Worker2.getlistup.connect(self.Updatelist)


        self.show()
   def Updatelist(self, bool_d0):
        pass


if __name__ == "__main__":
    
    app = QApplication(sys.argv)
    window = Yukleniyor()
    sys.exit(app.exec_())

from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys


options = webdriver.ChromeOptions()
options.add_argument('--headless') 

browser = webdriver.Chrome(options=options)

try:
    browser.get("https://uygulama.termolog.net/oturum-ac/?yeni")
    time.sleep(3)
    userInput = browser.find_element("xpath", "//*[@id='signin']/input[5]")
    passwordInput = browser.find_element("xpath", "//*[@id='signin']/input[6]")
    time.sleep(3)
    userInput.send_keys(user)
    passwordInput.send_keys(password)
    passwordInput.send_keys(Keys.ENTER)
    time.sleep(3)
except:
    print("HATA") 



from PyQt5.QtCore import *
from time import time
import termologsetup


class Worker2(QThread):
    
    getlistup = pyqtSignal(list)

    def run(self):

        browser = termologsetup.browser

        start_time = 0
        seconds =  20

        while True:

            current_time = time()
            
            if current_time - start_time > seconds:
                
                Value = []
                for i in (n+1 for n in range(20)):
                   
                    try:

                        CMTR_Value = browser.find_element("xpath", f"//*[@id='cember_genel_div']/div[{i}]/table/tbody/tr/td[1]/div/span")

                        Value.append(CMTR_Value.text) 
                        
                    except:

                        print("HATA")

                try:

                    browser.refresh()
                    
                except:

                    print("HATA")

                self.getlistup.emit(Value)           
                
                start_time = current_time
                
    def stop(self):
        self.quit()            
1 Answers

after reading your code, i am even more confused now, i managed to quit the selenium driver after its finished, also added some comments questioning some lines, we cant help you here if you dont help us, here's the final code:

from termolog import Worker2
# ihave look for termolog on the internnt and havent found it, could it be a user defined module?
class Yukleniyor(QMainWindow): # QMainWindow is undefined i assume its from termolog?
    def __init__(self):
        QMainWindow.__init__(self)
        self.ui = Ui_SplashScreen() # Ui_SplashScreen is undefined i assume its from termolog?
        self.ui.setupUi(self)


        self.Worker2 = Worker2 ()
        self.Worker2.start()
        self.Worker2.getlistup.connect(self.Updatelist)


        self.show()
    def Updatelist(self, bool_d0):
        pass


if __name__ == "__main__":
    
    app = QApplication(sys.argv) # QApplication is undefined i assume its from termolog?
    window = Yukleniyor()
    sys.exit(app.exec_()) # sys is being used here but neve imported

# ***************************
# this portion of the code makes sense and should work
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys


options = webdriver.ChromeOptions()
options.add_argument('--headless') 

browser = webdriver.Chrome(options=options)

try:
    browser.get("https://uygulama.termolog.net/oturum-ac/?yeni")
    time.sleep(3)
    userInput = browser.find_element("xpath", "//*[@id='signin']/input[5]")
    passwordInput = browser.find_element("xpath", "//*[@id='signin']/input[6]")
    time.sleep(3)
    userInput.send_keys(user) # user is never initialized or given a value
    passwordInput.send_keys(password) # password is never initialized or given a value
    passwordInput.send_keys(Keys.ENTER)
    time.sleep(3)
    
    browser.quit() # just add this to close the browser after your done

except:
    print("HATA") 
# ***************************


from PyQt5.QtCore import *
from time import time
import termologsetup # termologsetup is undefined i assume its user defined?


class Worker2(QThread):
    
    getlistup = pyqtSignal(list)

    def run(self):

        browser = termologsetup.browser

        start_time = 0
        seconds =  20

        while True:

            current_time = time()
            
            if current_time - start_time > seconds:
                
                Value = []
                for i in (n+1 for n in range(20)):
                   
                    try:

                        CMTR_Value = browser.find_element("xpath", f"//*[@id='cember_genel_div']/div[{i}]/table/tbody/tr/td[1]/div/span")

                        Value.append(CMTR_Value.text) 
                        
                    except:

                        print("HATA")

                try:

                    browser.refresh()
                    
                except:

                    print("HATA")

                self.getlistup.emit(Value)           
                
                start_time = current_time
                
    def stop(self):
        self.quit() # there is no quit method in QThread
# you need to learn more about object oriented programming, and more about web scraping  
Related