python - 如何使用 Python + Selenium 设置代理身份验证(用户和密码)

标签 python python-2.7 selenium-webdriver firefox proxy-authentication

我在 Python 2.7 中使用 Firefox WebDriver 和 Selenium。我的 python 程序启动 Firefox 浏览器并在运行该程序时访问不同的网站。但是,我需要设置带有身份验证的代理,这样当程序访问任何网站时,都会通过代理服务器访问。

SO上有一些类似的问题。但是,Python的Selenium Firefox WebDriver没有具体的解决方案。

最佳答案

重复:How to set proxy AUTHENTICATION username:password using Python/Selenium

Selenium 线:https://github.com/wkeeling/selenium-wire

安装 Selenium 线

pip install selenium-wire

导入

from seleniumwire import webdriver

代理授权

options = {
'proxy': {
    'http': 'http://username:password@host:port',
    'https': 'https://username:password@host:port',
    'no_proxy': 'localhost,127.0.0.1,dev_server:8080'
    }
}
driver = webdriver.Firefox(seleniumwire_options=options)

警告
查看 selenium-wire 缓存文件夹。我遇到了问题,因为它占用了我所有的磁盘空间。有时您需要在脚本中删除它。

关于python - 如何使用 Python + Selenium 设置代理身份验证(用户和密码),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38304253/

相关文章:

python - 在 Selenium 中迭代表非常慢

python - bs4 在给定标签的所有属性中搜索一个词

python - "Error 309"是什么意思?

python - 如何替换Django模板中的某些特定字符?

python - 尝试通过源代码开始跟踪 Python 特性和行为

python 模拟 : @wraps(f) problems

firefox - 我无法使用木偶驱动程序和Selenium 3在FireFox 48的下拉列表中选择选项

Python Pandas - 将带有 'series' 的 Dataframe 连接到另一个 Dataframe

python - 查找列表的平均值

python - str.__getslice__ 没有按预期工作,负停止