【问题标题】:Python Selenium Proxy doesn't change IP addressPython Selenium 代理不会更改 IP 地址
【发布时间】:2021-12-30 04:51:09
【问题描述】:

我正在尝试更改我的 IP 地址以绕过使用此代码抓取社交数据:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

if __name__ == '__main__':
    chromedriver_path = '/usr/local/bin/chromedriver'
    window_size = "1920,1080"
    chrome_options = Options()
    chrome_options.add_argument("--window-size=%s" % window_size)
  
    random_proxy = '124.240.187.80:82'
    webdriver.DesiredCapabilities.CHROME['proxy'] = {
        "httpProxy": random_proxy,
        "ftpProxy": random_proxy,
        "sslProxy": random_proxy,
        "proxyType": "MANUAL"
    }
   
    webdriver.DesiredCapabilities.CHROME['acceptSslCerts'] = True

    chromedriver = webdriver.Chrome(
        executable_path=chromedriver_path,
        options=chrome_options
    )

    chromedriver.get('https://whatismyip.com')

但它不起作用。我的 IP 地址保持不变。有什么建议吗? 非常感谢。

【问题讨论】:

    标签: python selenium selenium-webdriver web-crawler


    【解决方案1】:

    尝试使用 ChromeOptions 代替 Chrome 功能

    chrome_options = Options()
    chrome_options.add_argument(f'--proxy-server={random_proxy}')
    

    【讨论】:

    • 它不起作用。 WebDriverException:消息:未知错误:net::ERR_TUNNEL_CONNECTION_FAILED
    猜你喜欢
    • 2017-01-05
    • 2023-01-30
    • 2021-08-19
    • 2017-12-08
    • 1970-01-01
    • 2018-07-04
    • 1970-01-01
    • 2018-01-18
    • 1970-01-01
    相关资源
    最近更新 更多