在 Firefox 中使用授权代理与 Python 中的 Selenium

发布于 2025-01-18 16:30:36 字数 1560 浏览 1 评论 0原文

如何使用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:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文