简体   繁体   English

Selenium webdriver.Firefox(proxy = proxy)无效

[英]Selenium webdriver.Firefox(proxy=proxy) not effective

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/')

When directed to that website it still shows my local proxy. 当定向到该网站时,它仍然显示我的本地代理。 I got the above from the selenium site but it has not availed me. 我从硒站点获得了上述信息,但它无济于事。

EDIT: I just tried changing the format to proxy:port:user:pass and this time the proxy seems engaged since now the dialog box opened to input username and pass. 编辑:我只是尝试将格式更改为proxy:port:user:pass ,这一次代理似乎已生效,因为现在打开对话框以输入用户名并通过。 Well this is no good either. 嗯,这也不好。 Surely I don't need to try the roundabout way of focusing the alert and inputting the info there... 当然,我不需要尝试回旋方式来集中警报并在那里输入信息...

This is one of the working ways to setup proxy for firefox webdriver 这是为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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM