【问题标题】:Proxy in selenium python doesn't change my ipselenium python 中的代理不会更改我的 ip
【发布时间】:2023-01-30 20:53:43
【问题描述】:

我正在尝试在 selenium python 中使用代理,但是当我在显示我的 ip 的网页上测试代码时,代理不会更改我的 ip 地址。

这里有代码

import undetected_chromedriver as uc
from selenium import webdriver
from selenium.webdriver.chrome.options import Options


option = Options()
driver = uc.Chrome(options = option)

PROXY = "139.162.214.146"

option.add_argument('--proxy-server=%s' % PROXY)
option.add_argument('--disable-extensions')
option.add_argument('--disable-notifications')
option.add_argument('--no-sandbox')
option.add_argument('--disable-dev-shm-usage')
option.add_argument('--disable-gpu')
option.add_argument('--mute-audio')
option.add_argument('--ignore-certificate-errors')
option.add_argument('--disable-logging')

driver.get("https://www.whatismyip.com/")

input ()

代码应该更改 mi ip 但这并没有发生,我试图更改代理但问题是一样的。

【问题讨论】:

  • 在所有add_argument语句之后移动这行代码driver = uc.Chrome(options = option)。你也需要提供port。

标签: python selenium-webdriver proxy selenium-chromedriver


【解决方案1】:

我可以在这里看到多个问题。尝试使用以下代码:

import undetected_chromedriver as uc
from selenium import webdriver
from selenium.webdriver.chrome.options import Options


option = Options()

PROXY = "139.162.214.146"

option.add_argument('--proxy-server=%s' % PROXY)
option.add_argument('--disable-extensions')
option.add_argument('--disable-notifications')
option.add_argument('--no-sandbox')
option.add_argument('--disable-dev-shm-usage')
option.add_argument('--disable-gpu')
option.add_argument('--mute-audio')
option.add_argument('--ignore-certificate-errors')
option.add_argument('--disable-logging')

driver = uc.Chrome(options = option)

driver.get("https://www.whatismyip.com/")

input ()

另请注意,您需要为代理指定一个端口,如下所示:PROXY = "139.162.214.146:proxy_port"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-12
    • 1970-01-01
    • 1970-01-01
    • 2017-01-05
    • 1970-01-01
    • 1970-01-01
    • 2014-02-24
    • 2017-11-24
    相关资源
    最近更新 更多