【问题标题】:Selenium webdriver.Firefox(proxy=proxy) not effectiveSelenium webdriver.Firefox(proxy=proxy) 无效
【发布时间】:2015-11-30 21:51:35
【问题描述】:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.proxy import *

myProxy = "user:pass@proxy:port"

proxy = Proxy({
    'proxyType': ProxyType.MANUAL,
    'httpProxy': myProxy,
    'ftpProxy': myProxy,
    'sslProxy': myProxy,
    'noProxy': '' # set this value as desired
    })

driver = webdriver.Firefox(proxy=proxy)
driver.set_window_size(1024, 768)
driver.get('http://whois.urih.com/')

当定向到该网站时,它仍然显示我的本地代理。我从 selenium 网站获得了上述内容,但对我没有帮助。

编辑:我刚刚尝试将格式更改为proxy:port:user:pass,这次代理似乎已启用,因为现在打开了对话框以输入用户名并通过。好吧,这也不好。当然,我不需要尝试迂回的方式来集中警报并在那里输入信息......

【问题讨论】:

  • 我可能错了,难道httpProxy,ftpProxy等应该是主机,而用户名和密码应该在socksUsername和socksPassword中?
  • @KirilS。你是对的,我检查了firefox网络配置,我没有找到任何与代理用户名和密码相关的东西

标签: python selenium proxy


【解决方案1】:

这是为 firefox webdriver 设置代理的一种工作方式

from selenium import webdriver

firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference("network.proxy.type", 1)
firefox_profile.set_preference("network.proxy.http",ip) #set your ip
firefox_profile.set_preference("network.proxy.http_port", port) #set your port
driver = webdriver.Firefox(firefox_profile=firefox_profile)
driver.get(url) #target url

【讨论】:

  • 虽然我同意这是为 Firefox 正确配置代理的方法之一,但称其为“为硒设置代理的正确方法”是不正确的,而 OP 使用的方法是正确的。例如,使用这种方法,您需要为每个浏览器配置代理(IE、Chrome 将有不同的方式在浏览器级别设置代理),并且如果某个版本,您可能最终会拥有更多分支或不同版本的浏览器更改其代理的内部实现...
  • 如果我的代理 fromat 是:ip:port:user:pass,我应该如何设置它?目前还不清楚。或替代形式:user:pass@ip:port
  • @KirilS。我同意,但我尝试了许多不同的方法,这是唯一反映在 Firefox 上的方法
  • @RoryGillum 检查此链接stackoverflow.com/questions/17082425/…
  • 用户名和密码应该去哪里?除了将端口更改为 int 之外,其他线程没有提供关于上面发布的任何新信息。
猜你喜欢
  • 1970-01-01
  • 2016-08-05
  • 2017-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多