selenium 添加动态隧道代理
# 无须密码验证方法 chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_argument('--proxy-server=http://ip:port')
driver = webdriver.Chrome(chrome_options=chromeOptions)
密码验证(动态与隧道代理)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function from selenium import webdriver
from selenium.webdriver.chrome.options import Options def create_proxyauth_extension(proxy_host, proxy_port,
proxy_username, proxy_password,
scheme='http', plugin_path=None):
"""Proxy Auth Extension args:
proxy_host (str): domain or ip address, ie proxy.domain.com
proxy_port (int): port
proxy_username (str): auth username
proxy_password (str): auth password
kwargs:
scheme (str): proxy scheme, default http
plugin_path (str): absolute path of the extension return str -> plugin_path
"""
import string
import zipfile if plugin_path is None:
plugin_path = '/tmp/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="transfer.mogumiao.com",
proxy_port=9001,
proxy_username="username", # 输入隧道账号
proxy_password="passwod" # 输入密码
) co = Options()
co.add_argument("--start-maximized")
co.add_extension(proxyauth_plugin_path) driver = webdriver.Chrome(chrome_options=co)
driver.get("https://www.baidu.com/")
selenium 添加动态隧道代理的更多相关文章
- 关于selenium添加使用代理ip
最近在爬某个网站,发现这个网站的反爬太厉害了,正常时候的访问有时候都会给你弹出来验证,验证你是不是蜘蛛,而且requests发的请求携带了请求头信息,cookie信息,代理ip,也能识别是爬虫,他应该 ...
- python3 selenium模块Chrome设置代理ip的实现
python3 selenium模块Chrome设置代理ip的实现 selenium模块Chrome设置代理ip的实现代码: from selenium import webdriver chrome ...
- selenium+chromdriver 动态网页的爬虫
# 获取加载更多的数据有 2 种方法# 第一种就是直接找数据接口, 点击'加载更多' 在Network看下, 直接找到数据接口 # 第二种方法就是使用selenium+chromdriver # se ...
- ssh命令:隧道代理+本地端口转发+远程端口转发
0.前言 nc是一个在网络连接两端的好工具,同时也是也个临时的端口转发的好工具.(永久的端口转发用什么?用iptables) ssh也是这方面的好工具,好处是加密可靠可复用在一端操作即可,代价 ...
- Java设计模式---(动态)代理模式
代理设计模式 定义:为其他对象提供一种代理以控制对这个对象的访问. 动态代理使用 java动态代理机制以巧妙的方式实现了代理模式的设计理念. 之前虽然会用JDK的动态代理,但是有些问题却一直没有搞明白 ...
- 突破IP限制动态替换代理ip。
须要导入的两个jar包 实现的javabean <span style="font-size:18px;">package com.jx.po; public clas ...
- MFC如何在树形图边上添加动态小地图
MFC如何在树形图边上添加动态小地图 https://www.jianshu.com/p/7b1d828bf5db (简书无法识别缩进的...早知道先在博客园发了) (转载请注明出处) 作者:梦镜谷雨 ...
- springboot+shiro+redis(单机redis版)整合教程-续(添加动态角色权限控制)
相关教程: 1. springboot+shiro整合教程 2. springboot+shiro+redis(单机redis版)整合教程 3. springboot+shiro+redis(集群re ...
- QT中添加 动态库(.so) 和 静态库 (.a) 的方法
在QT 的Makefile文件中: 1 添加动态库,如lipcap.so 则,在LIBS一行中添加“-L/usr/local/lib -lpcap”,依据自己的情况修改libpcap.so的路径 2 ...
随机推荐
- anaconda3下64位python和32位python共存
查看当前工作平台:conda info 切换64位和32位: set CONDA_FORCE_32BIT=1是切换到32位 set CONDA_FORCE_32BIT= 是切换到64位 注意=号前后不 ...
- element 多个文件上传多次http请求解决方法
第一步 action="#" 第二步 :auto-upload = "false" 第三步 给元素绑定click事件触发提交方法,注意,把其他没有用的文件都给去 ...
- CnPack组件包的安装与使用
如果你用过Eclipse.NotePad++等等工具,再试试用刚装好Delphi写代码会很痛苦,你是否觉得Delphi的代码编辑器很不友好? 那就去了解一下CnPack吧,给你的Delphi装上它绝对 ...
- 用chrome和anywhere,配合安卓机搭建最简单的移动端页面测试。
很多时候,我们前端在写移动端页面的时候,虽然目前chrome有调试模式,可以模拟手机的部分效果,但仍有部分效果需要直接在手机上进行页面的调试,今天就在这里推荐一个适合windows+安卓的无需连接局域 ...
- android 事件绑定
layout布局设计了页面,如何绑定事件,与用户进行交互需要在Activity中进行处理. 下面的layout,有两个按钮. <LinearLayout android:layout_width ...
- 使用hibernate原生sql查询,结果集全为1的问题解决
问题如下: String sqlTest ="select summary,summaryno from F_Summary"; List<Map<Object, Ob ...
- angular js 初学
1 angularJS的一些概念 AngularJS 通过新的属性和表达式扩展了 HTML. AngularJS 是一个 JavaScript 框架,它是一个以Javascript编写的库,它可通过 ...
- vba data to input tool
public Sub InserDb() dim maxrow as integer dim maxcol as integer dim ddl as string dim recode as str ...
- 使用django发布带图片的网页(上)
如何使用django发布带静态图片的网页呢? 在settings.py里加入下面内容 STATIC_ROOT = os.path.join(os.path.dirname(__file__),'sta ...
- HQL包含中文查询失败
jdbc:mysql://172.16.9.6:3306/school?useUnicode=true&characterEncoding=UTF-8配置文件中的url加上编码,一般mysql ...