如何使用 Python + Selenium 设置代理身份验证(用户和密码) [英] How to set proxy authentication (user & password) using Python + Selenium

查看:67
本文介绍了如何使用 Python + Selenium 设置代理身份验证(用户和密码)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Firefox WebDriver in Python 2.7 with Selenium. My python program starts Firefox browser and visits different websites when I run the program. But, I need to set the proxy with authentication, so that when program visits any website, it will visit through the proxy server.

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

There are some similar questions on SO. But, there is no specific solution for Selenium Firefox WebDriver of Python.

推荐答案

Dup of: 如何使用 Python/Selenium 设置代理身份验证用户名:密码

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

安装 selenium-wire

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 缓存文件夹.我遇到了问题,因为它占用了我所有的磁盘空间.有时您必须根据需要在脚本中将其删除.

Warning
Take a look to the selenium-wire cache folder. I had a problem because it take all my disk space. You have to remove it sometimes in your script when you want.

这篇关于如何使用 Python + Selenium 设置代理身份验证(用户和密码)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆