带有 Bright Data chrome 驱动程序的 Selenium 代理

问题描述 投票:0回答:2

我尝试使用 BrightData、Selenium 和 Python 添加代理到 chrome 驱动程序,但由于某种原因效果不佳。我还必须添加用户和密码。 驱动程序工作正常,但是当我从驱动程序中看到我的 IP 时,显示的是我的公共 IP,而不是代理 IP。

        PROXY_HOST = 'xxxx' 
        PROXY_PORT = 'xxxx' 
        PROXY_USER = 'xxxx' 
        PROXY_PASS = 'xxxx' 

        PROXY = PROXY_HOST+':'+PROXY_PASS+'@'+PROXY_USER+':'+PROXY_PORT

        options = Options()
        options.headless = headless_mode
        options.add_argument("--window-size=1920,1200")
        options.add_experimental_option("excludeSwitches", ["enable-logging"])
        options.add_argument('--proxy-server=%s' % PROXY)

        driver = webdriver.Chrome(options = options, executable_path = DRIVER_PATH)
        driver.get('https://www.cual-es-mi-ip.net/')

        
python-3.x selenium selenium-webdriver proxy selenium-chromedriver
2个回答
1
投票

最后,我通过驱动程序“seleniumwire_options”中的参数更改了导入“from selenium.webdriver.chrome.options”。

 text_to_search = 'https://url-exemple.com'
        
 PROXY = PROXY_HOST+':'+PROXY_PASS+'@'+PROXY_USER+':'+PROXY_PORT
        
  options = {
     'proxy': {'https': 'http://'+PROXY,
     'https': 'https://'+PROXY},
 }

 driver = webdriver.Chrome(seleniumwire_options = options, executable_path = DRIVER_PATH)
 driver.get(text_to_search)

0
投票

Botasaurus 框架支持 SSL,其经过身份验证的代理 sych 为 http://username:password@proxy-provider-domain:port。

seleniumwire-vs-botasaurus

安装

pip install botasaurus

示例

from botasaurus import *

@browser(proxy="http://username:password@proxy-provider-domain:port") # TODO: Replace with your own proxy 
def visit_ipinfo(driver: AntiDetectDriver, data):
    driver.get("https://ipinfo.io/")
    driver.prompt()

visit_ipinfo()

您可以了解关于Botasaurus 这里

© www.soinside.com 2019 - 2024. All rights reserved.