Selenium 设置代理chrome
1.1. 连接无用户名密码认证的代理
from selenium import webdriver chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_argument('--proxy-server=http://localhost:8888')
driver = webdriver.Chrome(chrome_options=chromeOptions)
driver.get("https://www.cnblogs.com/Rita-LJ/p/8079094.html")
2. 有用户名和密码的连接
from selenium import webdriverdef 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 = 'd:/webdriver/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.crawlera.com",
proxy_port=8010,
proxy_username="fea687a8b2d448d5a5925ef1dca2ebe9",
proxy_password=""
) co = webdriver.ChromeOptions()
co.add_argument("--start-maximized")
co.add_extension(proxyauth_plugin_path) driver = webdriver.Chrome(chrome_options=co)
driver.get("http://www.amazon.com/")
以上直接通过python代码生成chrome所需的zip插件文件,IP端口用户名密码写上自己的,原文出处:
https://github.com/RobinDev/Selenium-Chrome-HTTP-Private-Proxy
Selenium 设置代理chrome的更多相关文章
- selenium设置代理,基于chrome浏览器
工作中遇到需要对项目中使用的selenium设置代理,跟大家分享一下. 1.下载chromeDriver:http://chromedriver.storage.googleapis.com/inde ...
- selenium 设置代理的话,可以使用这种方式,代码是我刚才测试过的,亲测可用
from selenium import webdriver chrome_options = webdriver.ChromeOptions() chrome_options.add_argumen ...
- selenium 设置代理ip
from selenium import webdriver options = webdriver.ChromeOptions() options.add_argument("--prox ...
- python3 selenium模块Chrome设置代理ip的实现
python3 selenium模块Chrome设置代理ip的实现 selenium模块Chrome设置代理ip的实现代码: from selenium import webdriver chrome ...
- selenium设置Chrome浏览器不出现通知,设置代理IP
from selenium import webdriver PROXY = "" chrome_options = webdriver.ChromeOptions() prefs ...
- selenium设置proxy、headers(phantomjs、Chrome、Firefox)
phantomjs 设置ip 方法1: service_args = [ '--proxy=%s' % ip_html, # 代理 IP:prot (eg:192.168.0.28:808) '--p ...
- selenium设置chrome和phantomjs的请求头信息
selenium设置chrome和phantomjs的请求头信息 出于反爬虫也好-跳转到手机端页面也好都需要设置请求头,那么如何进行呢? 目录 一:selenium设置phantomjs请求头: ...
- Selenium/HtmlUnit设置代理获取JS生成的网页
通常我们使用Java提供的HttpURLConnection或者Apache的HttpClient获取的网页源代码都是直观可见的,其代码的内容和通过浏览器右键网页->点击查看网页源代码的内容一致 ...
- charles 设置为chrome代理
本文参考:charles 设置为chrome代理 将charles设置为chrome的代理 需要注意的是,Chrome 和 Firefox 浏览器并不一定使用的就是本机,可能是一些代理工具,而 Cha ...
随机推荐
- 【学习笔记】--- 老男孩学Python,day8 知识点补充 join,列表不能循环删除,深浅copy
1. 补充基础数据类型的相关知识点 1. str. join() 把列表变成字符串 2. 列表不能再循环的时候删除. 因为索引会跟着改变 3. 字典也不能直接循环删除. 把要删除的内容记录在列表中. ...
- 记一次简单爬虫(豆瓣/dytt)
磕磕绊绊学python一个月,这次到正则表达式终于能写点有趣的东西,在此作个记录: ————————————————————————————————————————————————— 1.爬取豆瓣电影 ...
- windows 查看端口
windowsnetstat命令查看进程:netstat -ano查看占用端口进程:netstat -ano|findstr “端口号”,例子netstat -ano|findstr “8080”.t ...
- php递归获取分类结构
商城的菜单通常都是树状结构,我们来模仿实现以下. 原理都是相同的,所以我们来个简单点的结构就行.层级只有两层,有两大类:手机和电脑:每个大类下面分别有三个子类: //从数据库获取的分类数据(省略获取步 ...
- 微信支付报错:time_expire时间过短,刷卡至少1分钟,其他5分钟]
查了下代码: $input->SetTime_expire(date("YmdHis", time() + 600));//二维码过期时间.默认10min 10分钟,没问题. ...
- vue实现上传上删除压缩图片
<script> import {Config} from '@/config.js' import {mapState} from 'vuex' import {LocalData, t ...
- Vue项目中引用vue-resource步骤
直接上步骤: 1.通过命令,进入到当前项目所在目录 2.输入以下命令npm install vue-resource --save 3.安装完毕后,在main.js中导入,如下: import Vue ...
- ThinkPHP执行调用存储过程添加日志
本文出至:新太潮流网络博客 //PHP代码部分 /** * [LogAdd 操作日志] * @param [string] $userid [用户的ID] * @param [string] $typ ...
- 打开struts-config.xml 报错 解决方法Could not open the editor
打开struts-config.xml 报错 解决办法Could not open the editor 错误信息:Could not open the editor: Project XXX is ...
- Linux Transparent Huge Pages 对 Oracle 的影响
1 Transparent Huge Pages 说明 官网上有2篇文章对THP 做了说明: https://access.redhat.com/solutions/46111 https://acc ...