ultrafunkamsterdam / undetected-chromedriver

Custom Selenium Chromedriver | Zero-Config | Passes ALL bot mitigation systems (like Distil / Imperva/ Datadadome / CloudFlare IUAM)
https://github.com/UltrafunkAmsterdam/undetected-chromedriver
GNU General Public License v3.0
9.9k stars 1.16k forks source link

Hello im using undetectable chrome driver and it works perfectly except when im using it with with multipale theards it only interacts with 1 theard only which is the first one does anybody knows why ?! #682

Open Virusback opened 2 years ago

Virusback commented 2 years ago

Hello guys im using undetectable chrome driver and it works perfectly except when im using it with with multipale theards it only interacts with 1 theard only which is the first one does anybody knows why ?!

Here is my code for the config which i want to thearding it

  def Thread(self):
    try:
        threadsList = []
        for i in range(self.threadsCount):
            thread = Thread(target=self.Starter, name='Thread{}'.format(str(i + 1)))
            threadsList.append(thread)
        for eachThread in threadsList:
            eachThread.setDaemon(True)
            eachThread.start()
            sleep(self.sleepTime)
        for eachThread in threadsList:
            eachThread.join()
    except Exception as i:
        with self.lock:
            self.Error +=1
            with open('Error.txt', 'a') as error:
                error.write('Thread:' + str(i))
                error.write('\n')
                error.write('------------------------------------------------------')
                error.write('\n')  

def Config(self,eachCombo,phoneNumber,passWord,t2ked):
    try:
        chrome_options = uc.ChromeOptions()
        proxy = choice(self.proxyList)
        chrome_options.add_argument('--proxy-server=%s' % proxy)
        chrome_options.add_argument('--no-first-run --no-service-autorun --password-store=basic')

        #if self.headless == 'y' or self.headless == 'yes':
            #chrome_options.add_argument("--headless")
        #if self.proxyChoose == 'y' or self.proxyChoose == 'yes':
            #proxy = choice(self.proxyList)
            #chrome_options.add_argument('--proxy-server=%s' % proxy)
        #chrome_options.add_experimental_option('excludeSwitches', ['enable-logging', "enable-automation"])
        chrome_options.add_argument("--window-size=1920,1080")
        chrome_options.add_argument("----start-maximized")
        #if self.Incognito =='y' or self.Incognito == 'yes':
            #chrome_options.add_argument("--incognito")
        chrome_options.add_argument("--silent")
        # decleration of driver
        #ser=Service('chromedriver.exe')
        #driver = uc.Chrome()
        with uc.Chrome(options=chrome_options,use_subprocess=True) as driver:
            passChanged = False
            wait = WebDriverWait(driver=driver, timeout=10, poll_frequency=0.5,ignored_exceptions=[NoSuchElementException, ElementNotVisibleException,ElementNotInteractableException,StaleElementReferenceException])
            Action = ActionChains(driver)
            driver.get(f"https://accounts.google.com/signin/v2/identifier?flowName=GlifWebSignIn&flowEntry=ServiceLogin")
            sleep(1)
            wait.until(EC.visibility_of_element_located((By.NAME, 'identifier'))).send_keys(phoneNumber)
            sleep(2)
            driver.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/div/div[2]/div/div/div[2]/div/div[2]/div/div[1]/div/div/button/span').click()
            sleep(2)
            wait.until(EC.visibility_of_element_located((By.NAME, 'password'))).send_keys(passWord)
            sleep(2)
            driver.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/div/div[2]/div/div/div[2]/div/div[2]/div/div[1]/div').click()
            sleep(2)
            try:
                Confirm=wait.until(EC.visibility_of_element_located((By.XPATH, '/html/body/div[1]/div[1]/div[2]/div/div[2]/div/div/div[2]/div/div[1]/div/form/span/section/div/div/div/ul/li[3]/div'))).click()
            except:
                pass
            #sleep(2)

            try:
                wait.until(EC.visibility_of_element_located((By.XPATH, '/html/body/div[1]/div[1]/div[2]/div/div[2]/div/div/div[2]/div/div[1]/div/form/span/section/div/div/div[2]/div[1]/div/div[1]/div/div[1]/input'))).send_keys(t2ked)
                #sleep(1)
                okaftert2ked=wait.until(EC.visibility_of_element_located((By.XPATH, '/html/body/div[1]/div[1]/div[2]/div/div[2]/div/div/div[2]/div/div[2]/div/div[1]/div/div/button'))).click()
                #sleep(1)
            except:
                pass
            #sleep(2)
            try:
                okaftert2ked=wait.until(EC.visibility_of_element_located((By.XPATH, '/html/body/div[1]/div[1]/div[2]/div/div[2]/div/div/div[2]/div/div[2]/div/div[1]/div/div/button'))).click()
                #sleep(1)
            except:
                pass
            #sleep(2)
            try:
                notnow=wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/c-wiz/div/div/div/div[2]/div[4]/div[1]/button'))).click()
                #sleep(1)
            except:
                pass
            #sleep(2)
            try:
                confirmS=wait.until(EC.visibility_of_element_located((By.XPATH, '/html/body/c-wiz[2]/c-wiz/div/div[1]/div/div/div/div[2]/div[3]/div/div[2]/div'))).click()
                #sleep(1)
            except:
                pass
            driver.get(self.mainURL)
            sleep(2)
            driver.refresh()
            sleep(1)
            window_before = driver.window_handles[0]
            try:
                userNameInput = wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div/div/header/div[2]/div[2]/button'))).click()
                sleep(2)
                gmailt = wait.until(EC.element_to_be_clickable((By.XPATH, '//div[@class="login-menu"]//div[contains(@class,"S9gUrf-YoZ4jf")]'))).click()
            except:
                pass

            window_after = driver.window_handles[1]
            sleep(1)
            driver.switch_to.window(window_after)
            try:
                gmailtt = wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div[1]/div/div/main/div[2]/div/div[1]/div[1]/div[1]/div[3]'))).click()
                sleep(1)
            except:
                pass
            try:
                gmailttt = wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div[1]/div/div/main/div[4]/div[1]'))).click()
            except:
                pass
            try:
                waitButton = wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div/div/div/div/div[1]/div[1]/div[2]/div[1]/div/div[1]/div[4]/button[1]/span[1]'))).click()
            except:
                pass
            try:
                sleep(5)
                driver.implicitly_wait(3)
                followButton = driver.find_element(By.XPATH, '//div[contains(@class,"room-host-about")]//div[@class="host-follow-btn"]')
                sleep(2)
                followButton.click()
            except:
                pass
            while True:
                try:
                    for i in range(10):
                        try:
                            try:
                                driver.implicitly_wait(3)
                                commentInput = driver.find_element(By.XPATH, '/html/body/div/div/div/div/div/div[1]/div[2]/div[2]/div/textarea')
                                sleep(2)
                                commentInput.send_keys(choice(self.commentsList))
                                sleep(2)
                                sendButton = driver.find_element(By.XPATH, '/html/body/div/div/div/div/div/div[1]/div[2]/div[2]/div/a').click()
                            except:
                                pass
                        except:
                            continue
                        finally:
                            sleep(self.commentDelay)
                except:
                    continue
            input('')
    except Exception as exceptionErr:
        if 'HTTPConnectionPool' in str(exceptionErr) or 'HTTPSConnectionPool' in str(exceptionErr):
            with self.lock:
                self.Error += 1
                self.myQueue.put(eachCombo)
        elif 'list index out of range' in str(exceptionErr):
            with self.lock:
                self.Error += 1
                self.myQueue.put(eachCombo)
        else:
            with self.lock:
                self.Error += 1
                self.myQueue.put(eachCombo)
                with open('Error.txt', 'a',encoding='utf-8',errors='ignore') as error:
                    error.write('config exception')
                    error.write('\n')
                    error.write(str(exceptionErr))
                    error.write('\n')
                    error.write(str(eachCombo))
                    error.write('\n')
                    error.write('---------------------------------------------')
                    error.write('\n')

if name == 'main': FacebookNumberRemover()

Virusback commented 2 years ago

@ultrafunkamsterdam

Wamy-Dev commented 2 years ago

Please do not @ the dev. Here is the problem from what I know. Threading in python, and in other languages for that matter, is extremely finicky. A lot of modules only work on one thread to begin with, and most modules have to be built with threading in mind, which I suspect chrome driver itself, is not.

Virusback commented 2 years ago

Please do not @ the dev. Here is the problem from what I know. Threading in python, and in other languages for that matter, is extremely finicky. A lot of modules only work on one thread to begin with, and most modules have to be built with threading in mind, which I suspect chrome driver itself, is not.

So is there is a way to pass this problem or its not possible

Wamy-Dev commented 2 years ago

based on my experience and what I know about threading, I don't think it is possible. I don't even think you can do it with normal selenium.

DGaffney commented 2 years ago

Yeah, I would run multiple instances and control concurrency outside the scope of the execution of this code. This is almost certainly a recipe for disaster

Virusback commented 2 years ago

based on my experience and what I know about threading, I don't think it is possible. I don't even think you can do it with normal selenium.

no it works peferctly with the normal selenium but the normal selenium dosent provide gmail login

sebdelsol commented 2 years ago

It works perfectly with undetected-chromedriver too : I use multi-thread a lot without any issues.

Please stick to best practices for bugs reporting : you're supposed to show the minimum running code to reproduce the issue and not a wall of barely formatted code with parts missing to make it runs.

The code you provided is not complete and it's so messy I don't know where to begin...