【问题标题】:Using proxies in selenium python在 selenium python 中使用代理
【发布时间】:2021-02-07 06:01:44
【问题描述】:

我正在尝试使用 selenium 使用我找到的代码更改我的 IP 但我收到一个错误: selenium.common.exceptions.WebDriverException:消息:“chromedriver”可执行文件需要在 PATH 中 `从硒导入网络驱动程序

PROXY = "23.23.23.23:3128" # IP:PORT 或 HOST:PORT

chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--proxy-server=http://%s' % PROXY)

chrome = webdriver.Chrome(chrome_options=chrome_options) chrome.get("http://whatismyipaddress.com")`

【问题讨论】:

    标签: python selenium


    【解决方案1】:

    在这里,我希望它有所帮助:)

    from selenium import webdriver
    from selenium.webdriver.common.proxy import Proxy, ProxyType
    
    prox = Proxy()
    prox.proxy_type = ProxyType.MANUAL
    prox.http_proxy = "ip_addr:port"
    prox.socks_proxy = "ip_addr:port"
    prox.ssl_proxy = "ip_addr:port"
    
    capabilities = webdriver.DesiredCapabilities.CHROME
    prox.add_to_capabilities(capabilities)
    
    driver = webdriver.Chrome(desired_capabilities=capabilities)
    

    【讨论】:

    • 您好,感谢您的评论,但它一直给我错误''chrome driver' executable needs to be in PATH'。
    • 试试这个驱动 = webdriver.chrome(executable_path=r"path")
    【解决方案2】:

    我通过将可执行路径添加到 chrome 变量解决了这个错误

    这是我的代码:

    from selenium import webdriver
    from selenium.webdriver.common.proxy import Proxy, ProxyType
    
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument('--proxy-server=ipaddress:port')
    driver = webdriver.Chrome(executable_path="your executable path",chrome_options=chrome_options)
     driver.get('https://www.myip.com/')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 2021-10-12
      • 1970-01-01
      相关资源
      最近更新 更多