【问题标题】:Undetected ChromeDriver with Proxy使用代理未检测到 ChromeDriver
【发布时间】:2023-02-15 01:25:03
【问题描述】:

当我将代理与 undetected-chromedriver-v2 一起使用时,我看到 CloudFlare bot protect screen。如何使用代理绕过 cloudflare 屏幕。我想使用代理,如何解决这个问题?

代码:

from seleniumwire.undetected_chromedriver.v2 import Chrome
import time
from selenium_stealth import stealth

id="proxyid"
password="proxypw"
ip="proxyip"
port="proxyport"
def proxy_test():
        options = {
        'proxy': {
                'https': "https://"+id+":"+password+"@"+ip+":"+port,
                'https': "https://"+id+":"+password+"@"+ip+":"+port,
                'no_proxy': 'localhost,127.0.0.1'
        }
        }

        driver = Chrome(seleniumwire_options=options)
        
        stealth(driver,
        languages=["en-US", "en"],
        vendor="Google Inc.",
        platform="Win32",
        webgl_vendor="Intel Inc.",
        renderer="Intel Iris OpenGL Engine",
        fix_hairline=True,
        )
        driver.get("https://csgocases.com/")

        time.sleep(100)

def main():
    proxy_test()

if __name__ == '__main__':
    main()

【问题讨论】:

    标签: python selenium selenium-webdriver proxy undetected-chromedriver


    【解决方案1】:

    尽管您要求使用 undetected-chromedriver,但我为您提供了另一种解决方案。而且,selenium-stealth 有时会被检测到并使情况变得更糟。

    • 还可能出现一个问题,即您的代理被列入黑名单。在那种情况下,我建议您购买一些便宜的住宅代理,例如来自asocks(按使用付费)

    • 对于身份验证本身,您将使用Selenium-Profiles,目前 cloudfare 和其他人也未检测到它。

    from selenium_profiles.driver import driver as mydriver
    from selenium_profiles.profiles import profiles
    from selenium.webdriver.common.by import By  # locate elements
    
    mydriver = mydriver()
    profile = profiles.Windows() # or .Android
    
    
    host = "193.123.98.126" # IP
    port = 8080
    user = "user"
    password = "pass"
    scheme="http"
    
    
    auth_proxy = {"host":host,"port":port,"username":user, "password":password, "scheme":scheme}
    
    profile["options"]["extensions"] = {"auth_proxy":auth_proxy}
    
    driver = mydriver.start(profile, uc_driver=False)
    
    driver.get("http://lumtest.com/myip.json")
    
    
    # quit driver
    input('Press ENTER to quit Driver
    ')
    driver.quit()
    

    【讨论】: