芝麻HTTP:设置Selenium+Chrome代理
微博登录限制了错误次数···加上Cookie大批账号被封需要从Cookie池中 剔除被封的账号··· 需要使用代理··· 无赖百度了大半天都是特么的啥玩意儿???结果换成了 Google手到擒来 分分钟解决(那么问题来了?百度除了卖假药还会干啥?)
Selenium+Chrome认证代理不能通过options处理。只能换个方法使用扩展解决
原文地址:https://stackoverflow.com/questions/29983106/how-can-i-set-proxy-with-authentication-in-selenium-chrome-web-driver-using-pyth#answer-30953780 (Stack Overflow 这是个好地方啊)
# -*- coding: utf- -*-
# @Time : // :
# @Author : 哎哟卧槽
# @Site :
# @File : pubilc.py
# @Software: PyCharm
import string
import zipfile
def create_proxyauth_extension(proxy_host, proxy_port,
proxy_username, proxy_password,
scheme='http', plugin_path=None):
"""代理认证插件
args:
proxy_host (str): 你的代理地址或者域名(str类型)
proxy_port (int): 代理端口号(int类型)
proxy_username (str):用户名(字符串)
proxy_password (str): 密码 (字符串)
kwargs:
scheme (str): 代理方式 默认http
plugin_path (str): 扩展的绝对路径
return str -> plugin_path
"""
if plugin_path is None:
plugin_path = 'vimm_chrome_proxyauth_plugin.zip'
manifest_json = """
{
"version": "1.0.0",
,
"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
使用方法:
from selenium import webdriver
from common.pubilc import create_proxyauth_extension
proxyauth_plugin_path = create_proxyauth_extension(
proxy_host="XXXXX.com",
proxy_port=,
proxy_username="XXXXXXX",
proxy_password="XXXXXXX"
)
co = webdriver.ChromeOptions()
# co.add_argument("--start-maximized")
co.add_extension(proxyauth_plugin_path)
driver = webdriver.Chrome(executable_path="C:\chromedriver.exe", chrome_options=co)
driver.get("http://ip138.com/")
print(driver.page_source)
无认证代理:
options = webdriver.ChromeOptions()
options.add_argument('--proxy-server=http://ip:port')
driver = webdriver.Chrome(executable_path="C:\chromedriver.exe", chrome_options=0ptions)
driver.get("http://ip138.com/")
print(driver.page_source)
芝麻HTTP:设置Selenium+Chrome代理的更多相关文章
- 芝麻HTTP:爬虫之设置Selenium+Chrome代理
微博登录限制了错误次数···加上Cookie大批账号被封需要从Cookie池中 剔除被封的账号··· 需要使用代理··· 无赖百度了大半天都是特么的啥玩意儿???结果换成了 Google手到擒来 分分 ...
- 小白学爬虫-设置Selenium+Chrome代理
微博登录限制了错误次数···加上Cookie大批账号被封需要从Cookie池中 剔除被封的账号··· 需要使用代理··· 无赖百度了大半天都是特么的啥玩意儿???结果换成了 Google手到擒来 分分 ...
- charles 设置为chrome代理
本文参考:charles 设置为chrome代理 将charles设置为chrome的代理 需要注意的是,Chrome 和 Firefox 浏览器并不一定使用的就是本机,可能是一些代理工具,而 Cha ...
- Selenium Chrome浏览器的启动以及proxy设置
Selenium Chrome浏览器的启动以及proxy设置 虽然WebDriver对Firefox的支持最好,之前写的脚本也都在Firefox浏览器运行,但最近项目做了整合,发现新整合的功能不太 ...
- python爬虫——selenium+chrome使用代理
先看下本文中的知识点: python selenium库安装 chrome webdirver的下载安装 selenium+chrome使用代理 进阶学习 搭建开发环境: selenium库 chro ...
- 芝麻HTTP:在无GUI的CentOS上使用Selenium+Chrome
各位小伙伴儿的采集日常是不是被JavaScript的各种点击事件折腾的欲仙欲死啊?好不容易找到个Selenium+Chrome可以解决问题! 但是另一个▄█▀█●的事实摆在面前,服务器都特么没有GUI ...
- 小白学爬虫-在无GUI的CentOS上使用Selenium+Chrome
爬虫代理IP由芝麻HTTP服务供应商提供各位小伙伴儿的采集日常是不是被JavaScript的各种点击事件折腾的欲仙欲死啊?好不容易找到个Selenium+Chrome可以解决问题! 但是另一个▄█▀█ ...
- python3 + selenium + (chrome and firefox)使用
目录 瞎扯一句 简介 最后放模板 瞎扯一句 最近在做一个关于 selenium 相关的项目,在选择浏览器方面,一般有3种方案: chrome phantomJs firefox(推荐) 网上有很多教程 ...
- 笔记-selenium+chrome headless
笔记-selenium+chrome headless 1. selenium+chrome headless phantomjs与selenium分手了,建议使用其它无头浏览器. chro ...
随机推荐
- python函数式编程之装饰器(一)
1.开放封闭原则 简单来说,就是对扩展开放,对修改封闭 在面向对象的编程方式中,经常会定义各种函数. 一个函数的使用分为定义阶段和使用阶段,一个函数定义完成以后,可能会在很多位置被调用 这意味着如果函 ...
- .NET Core 2.0 问题杂记
一. Ubuntu 14.04 安装 1.安装之前请先删除之前的.net core 版本 命令如下: 1.1 获取安装的.net core 版本 sudo apt --installed list | ...
- AutoDesk Forge 获取令牌认证
创建应用程序 在开始使用Forge Platform之前,您需要设置一个应用程序并获取您的客户端ID和密码. 步骤1:登录Dev Portal 去开发门户网站:https://developer.au ...
- #1280 : Rikka with Sequence II [meet int the middle]
tle弃疗了 等着回学校找个标程拍一下吧 #include <iostream> #include <cstdio> #include <cstring> #inc ...
- POJ 3304 Segments[直线与线段相交]
Segments Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13514 Accepted: 4331 Descrip ...
- getHibernateTemplate() VS getSession()
如题所示,对于这个问题,官网文档已给出答案,详见: /** * Obtain a Hibernate Session, either from the current transaction or * ...
- 浅学vue
因之前项目接触了vue,从此我被迷住,简洁而不失优雅,小巧而不乏大匠. 首先我们要了解vue,什么是vue,正如官网所说:Vue.js 是一套构建用户界面的渐进式框架,Vue 的核心库只关注视图层.V ...
- apache 改变文档根目录www的位置
1.找到apache的安装目录,找到config/httpd.conf,找到DocumentRoot "D:/wamp/www/" 改成你想要的目录,例如:改成 DocumentR ...
- CentOS时间的查看与修改
[http://www.centoscn.com/CentOS/help/2014/0805/3430.html] 1.查看.修改Linux时区与时间 一.linux时区的查看与修改 1,查看当前时区 ...
- ansible实践4- 管理配置文件
生产环境中大多时候是需要管理配置文件的,安装软件包只是在初始化环境的时候用一下.下面我们来写个管理nginx配置文件的playbook mkdir -p /etc/ansible/nginx_c ...