from selenium import webdriver
import string
import zipfile
# 打包Google代理插件
def create_proxyauth_extension(proxy_host, proxy_port, proxy_username, proxy_password, scheme='http', plugin_path=None):
if plugin_path is None:
# 插件地址
plugin_path = 'C:/Program Files (x86)/Google/Chrome/Application/vimm_chrome_proxyauth_plugin.zip' manifest_json = """
{
"version": "1.0.0",
"manifest_version": 2,
"name": "Chrome Proxy",
"permissions": [
"proxy",
"tabs",
"unlimitedStorage",
"storage",
"<all_urls>",
"webRequest",
"webRequestBlocking"
],
"background": {
"scripts": ["background.js"]
},
"minimum_chrome_version":"22.0.0"
}
""" background_js = string.Template(
"""
var config = {
mode: "fixed_servers",
rules: {
singleProxy: {
scheme: "${scheme}",
host: "${host}",
port: parseInt(${port})
},
bypassList: ["foobar.com"]
}
}; chrome.proxy.settings.set({value: config, scope: "regular"}, function() {}); function callbackFn(details) {
return {
authCredentials: {
username: "${username}",
password: "${password}"
}
};
} chrome.webRequest.onAuthRequired.addListener(
callbackFn,
{urls: ["<all_urls>"]},
['blocking']
);
"""
).substitute(
host=proxy_host,
port=proxy_port,
username=proxy_username,
password=proxy_password,
scheme=scheme,
)
with zipfile.ZipFile(plugin_path, 'w') as zp:
zp.writestr("manifest.json", manifest_json)
zp.writestr("background.js", background_js) return plugin_path # 填写主机地址,端口,账号,密码
proxyauth_plugin_path = create_proxyauth_extension(
proxy_host="****",
proxy_port=808,
proxy_username="****",
proxy_password="****"
)
# 测试
co = webdriver.ChromeOptions()
co.add_argument("--start-maximized")
co.add_extension('C:/Program Files (x86)/Google/Chrome/Application/vimm_chrome_proxyauth_plugin.zip')
driver = webdriver.Chrome(chrome_options=co)
driver.get("http://www.google.cn/")

python3 - selenium 添加有账号密码的代理的更多相关文章

  1. python3 mqtt 添加用户名以及密码

    import paho.mqtt.client as mqtt client = mqtt.Client(client_id, transport='tcp') client.username_pw_ ...

  2. openvpn部署账号密码登录

    1.开启服务器端路由转发功能: 修改配置文件/etc/sysctl.conf中 net.ipv4.ip_forward = 0 改为 net.ipv4.ip_forward = 1 [root@nod ...

  3. PHP CURL 账号密码 添加授权Authorization头Header

    <?phpfunction http_request_xml($url,$data = null,$arr_header = null){ $curl = curl_init(); curl_s ...

  4. Linux下添加FTP账号和服务器、增加密码和用户,更改FTP目录

    1. 启动VSFTP服务器 A:cenos下运行:yum  install  vsftpd B. 登录Linux主机后,运行命令:”service vsftpd start” C. 要让FTP每次开机 ...

  5. chromedriver 代理设置(账号密码)

    在使用selenium时遇到的一个问题 如何为chromedriver设置有密码的代理 在借鉴了stackoverflow上的答案 background.js var config = { mode: ...

  6. selenium(python)登录时账号密码错误提示语

    selenium(python)登录时账号密码错误提示语的获取 可以用text

  7. 使用selenium进行密码破解(绕过账号密码JS加密)

    经常碰到网站,账号密码通过js加密后进行提交.通过burp拦截抓到的账号密码是加密后的,所以无法通过burp instruder进行破解.只能模拟浏览器填写表单并点击登录按钮进行破解.于是想到了自动化 ...

  8. 【转】Linux下添加FTP账号和服务器、增加密码和用户,更改FTP目录

    转自:http://blog.csdn.net/cloudday/article/details/8640234   1. 启动VSFTP服务器 A:cenos下运行:yum  install  vs ...

  9. python3 selenium模块Chrome设置代理ip的实现

    python3 selenium模块Chrome设置代理ip的实现 selenium模块Chrome设置代理ip的实现代码: from selenium import webdriver chrome ...

随机推荐

  1. TeamViewer如何绑定谷歌二次验证码/谷歌身份验证?

    1.下载TeamViewer,找到谷歌二次验证界面 下载.注册TeamViewer后,点击右上角账户名-“编辑配置文件” [常规]-“双重验证”,点“启用”   进入[激活双重验证]界面,点“启动激活 ...

  2. 聊一聊Flutter的setState()

    Flutter 里面包含两种widget 一种可变的,一种不可变的: 在可变的widget中可以使用 setstate(){} 函数. 官方也给出了例子: _onClick(){ setState() ...

  3. 为什么不应该使用goroutine id?

    Goroutine id 的获取方式 之前做的项目中,会使用 goroutine-id(以下简称 goid) 作为日志中的一个标识参数.而 goroutine 的相关信息是不对外暴露的.想要获取 go ...

  4. IO流——转换流、缓冲流

    一.转换流 1. OutputStreamWriter类 属于字符输出流,OutputStreamWriter 是字符流通向字节流的桥梁:可使用指定的字符编码表,将要写入流中的字符编码成字节. 它的作 ...

  5. CentOS6下yum搭建LNMP环境

    1.关闭防火墙[root@CentOS ~]# chkconfig iptables off 2.关闭selinuxvi /etc/sysconfig/selinux //将SELINUX=enfor ...

  6. Numpy数组的函数

    import numpy as np # 将 0~100 10等分 x = np.arange(0,100,10) # array([ 0, 10, 20, 30, 40, 50, 60, 70, 8 ...

  7. pandas_时间序列和常用操作

    # 时间序列和常用操作 import pandas as pd # 每隔五天--5D pd.date_range(start = '',end = '',freq = '5D') ''' Dateti ...

  8. PDO::commit

    PDO::commit提交一个事务(PHP 5 >= 5.1.0, PECL pdo >= 0.1.0) 说明 语法 bool PDO::commit ( void )高佣联盟 www.c ...

  9. QDC day4

    图论. 强连通图 与 弱连通图 . 最短路 .dij 不支持负权.显然 值得一提的是利用斐波那契堆m+nlogn . 一张 边权都是2的整数次幂 考虑 一下直接 结构体维护这个2的整次幂数组但比大小 ...

  10. 关于 ORA-01033: ORACLE initialization or shutdown in progress

    第一步:   这个错误首先查看服务进程是否正常启动: 第二步:   一般情况下第一步都没问题,问题出在可能误删了日志文件: 当然可能不是你删除的,可能被某些清理软件删除的: 或者是其他情况导致日志出错 ...