在 Firefox 中使用授权代理与 Python 中的 Selenium
如何使用Python中的selenium向Firefox中的代理服务器提供用户名和密码?
我尝试了下面的代码,但 IP 地址没有改变。我检查了 Firefox 中的代理设置,它显示仅更改了 http 代理,但未更改 https。
proxy = {'host': '111.111.111.11',
'port': 8080,
'usr': USERNAME,
'pwd': PASSWORD
}
profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", proxy['host'])
profile.set_preference("network.proxy.https", proxy['host'])
profile.set_preference("network.proxy.http_port", proxy['port'])
profile.set_preference("network.proxy.username", proxy['usr'])
profile.set_preference("network.proxy.password", proxy['pwd'])
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile=profile)
driver.get('https://whatismyipaddress.com')
我看到了 ChromeDriver 解决方案 (但我没有测试它,因为我只能使用 Firefox):
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=196.19.8.80:8000')
chrome_options.add_argument('--proxy-auth=yjd5Rn:29apJZ')
chrome = webdriver.Chrome(chrome_options=chrome_options)
chrome.get("http://whatismyipaddress.com")
如您所见,ChromeOptions 有 '--proxy-auth=yjd5Rn:29apJZ' 参数。
谁能告诉我如何使用代理并在 Firefox 中使用 Selenium 和 python 向代理服务器提供授权?提前致谢!
以下是代理服务器的登录页面:
How to provide Username and Password to a proxy server in Firefox with selenium in python?
I tried the code below but the IP address doesn't change. I check the proxy setting in Firefox, it shows that only http proxy is changed, but not https.
proxy = {'host': '111.111.111.11',
'port': 8080,
'usr': USERNAME,
'pwd': PASSWORD
}
profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", proxy['host'])
profile.set_preference("network.proxy.https", proxy['host'])
profile.set_preference("network.proxy.http_port", proxy['port'])
profile.set_preference("network.proxy.username", proxy['usr'])
profile.set_preference("network.proxy.password", proxy['pwd'])
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile=profile)
driver.get('https://whatismyipaddress.com')
I see a solution for ChromeDriver (but I don't test it because I can only use Firefox):
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=196.19.8.80:8000')
chrome_options.add_argument('--proxy-auth=yjd5Rn:29apJZ')
chrome = webdriver.Chrome(chrome_options=chrome_options)
chrome.get("http://whatismyipaddress.com")
As you can see, ChromeOptions have '--proxy-auth=yjd5Rn:29apJZ' argument.
Could anyone tell me how to use proxy and provide authorization to proxy server in Firefox with Selenium and in python? Thanks in advance!
Below is the login page from the proxy server:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论