程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

未被检测到的 ChromeDriver 在 Selenium 中使用时仍会激活验证码

发布于2024-11-10 09:29     阅读(867)     评论(0)     点赞(26)     收藏(4)


基本上,我尝试登录 Snapchat,但每次都会触发验证码,因此为了避免这种情况,我在这里阅读了有关未检测到的 chrome 驱动程序的信息:https: //github.com/ultrafunkamsterdam/undetected-chromedriver/blob/master/undetected_chromedriver/devtool.py

我决定尝试一下,但验证码仍然被激活......下面是我的代码:

import undetected_chromedriver as uc
self.driver = uc.Chrome()

def login(self):
        print('GET LOGIN')
        self.driver.get("https://accounts.snapchat.com/accounts/v2/login")

        print(self.user_creds['username'])
        try:
            accept_all_button = self.driver.find_element(By.XPATH, "//button[span[contains(text(), 'Accept All')]]")
            accept_all_button.click()
            print("Clicked 'Accept All' button to remove overlapping elements.")
            time.sleep(5)  # Wait for the page to update
        except Exception as e:
            print(f"'Accept All' button not found, proceeding to click 'Accept' button.{e}")

        # Wait for the username input to be present
        WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located((By.NAME, "accountIdentifier"))
        )
        print('found 1')
        username_input = self.driver.find_element(By.NAME, "accountIdentifier")
        
        username_input.send_keys(self.user_creds['username'])
        print('found 2',username_input)
        time.sleep(3)
        next_button =WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable((By.XPATH, "//button[contains(text(), 'Next')]"))
        )
        #next_button = self.driver.find_element(By.CSS_SELECTOR, "btn.btn-lg.btn-default")
        print("next",next_button)
        
        time.sleep(2)  # Give some time for the scrolling to complete
        next_button.click()

        print('found 3')
       
        time.sleep(10)
        
        try:
            WebDriverWait(self.driver, 10).until(
                EC.presence_of_element_located((By.XPATH, "//h1[@class='login-challenge-title' and contains(text(), 'Log in to Snapchat')]"))
            )
            print("Element found: Log in to Snapchat")
        except Exception as e:
            print("Element not found: Log in to Snapchat")

        password_input = WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located((By.NAME, "password"))
        )
        password_input.send_keys(self.user_creds['password'])
        password_input.send_keys(Keys.RETURN)
        print('found 4')
        # Wait for some time to ensure login is processed
        time.sleep(10)
        
        print("Logged in successfully!")

有人有使用这个包并绕过验证码的经验吗?


解决方案


暂无回答



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:https://www.pythonheidong.com/blog/article/2045415/c943c74b3a3471437cc9/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

26 0
收藏该文
已收藏

评论内容:(最多支持255个字符)