微博登录限制了错误次数···加上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-8 -*-
# @Time : 2017/11/15 9:50
# @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",
"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
使用方法:
from selenium import webdriver
from common.pubilc import create_proxyauth_extension
proxyauth_plugin_path = create_proxyauth_extension(
proxy_host="XXXXX.com",
proxy_port=9020,
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)
以上完毕 So Easy
分享到:
相关推荐
09_selenium+Chrome登陆...selenium+Chrome登陆豆瓣案例.py09_selenium+Chrome登陆豆瓣案例.py09_selenium+Chrome登陆豆瓣案例.py09_selenium+Chrome登陆豆瓣案例.py09_selenium+Chrome登陆豆瓣案例.py09_selenium+Ch
Java开发案例-springboot-44-整合Selenium访问百度-源代码+文档.rar Java开发案例-springboot-44-整合Selenium访问百度-源代码+文档.rar Java开发案例-springboot-44-整合Selenium访问百度-源代码+文档.rar Java开发...
京东商品爬虫-淘宝店铺爬虫(selenium+python实现) 【爬虫】基于selenium+python实现京东商品爬虫-淘宝店铺爬虫.zip 【爬虫】基于selenium+python实现京东商品爬虫-淘宝店铺爬虫.zip 【爬虫】基于selenium+python...
最近在搭建python+selenium+chrome自动化测试,整理了相应的工具。 python版本是3.7.2 工具包含:chromedriver_win32 selenium-3.141.0.tar.gz PyInstaller-3.4.tar.gz 72.0.3626.109_chrome_installer.exe
selenium+chromedriver120.0.6046.0-win64+python测试代码 项目介绍: 该案例是利用selenium使用xls中的数据对表单自动化填充及提交 项目中用到了chromedriver版本为120.0.6046.0系统win10 64位,需要安装谷歌浏览器...
基于selenium+python实现京东商品爬虫淘宝店铺爬虫项目源码基于selenium+python实现京东商品爬虫淘宝店铺爬虫项目源码基于selenium+python实现京东商品爬虫淘宝店铺爬虫项目源码基于selenium+python实现京东商品爬虫...
【标题】"selenium+JAVA+chrome自动化测试demo"揭示了这个项目是关于使用Selenium WebDriver结合Java语言来实现Chrome浏览器的自动化测试。Selenium是一个强大的开源自动化测试框架,允许开发者编写可运行在多种...
下面将详细介绍如何通过Python结合Selenium和Chrome浏览器设置地理定位(即经纬度)来自动发布抖音视频。 首先,`selenium`是一个强大的Web自动化测试框架,它可以模拟真实用户的浏览器操作,如点击、滚动、填写...
基于scrapy+scrapy-redis+selenium+pandas+matplotlibaqi天气信息爬虫、清洗资料齐全+详细文档+源码.zip 【备注】 1、该项目是个人高分项目源码,已获导师指导认可通过,答辩评审分达到95分 2、该资源内项目代码都...
python爬虫-selenium详解, python爬虫-selenium详解, python爬虫-selenium详解
【标题】"selenium webdriver+chrome插件.zip" 涉及的核心知识点是Selenium WebDriver,特别是它在Chrome浏览器中的应用以及与Firefox的交互。这个压缩包包含了Selenium IDE的Chrome插件,以及对应的WebDriver驱动...
Selenium+Chrome爬取中国青年网新闻内容,内含代码解释文档;该文件,主要是利用Selenium+Chrome爬取中国青年网的新闻链接,插入数据库,并根据链接爬取链接下的新闻内容再插入到数据库中,数据库使用的是MySQL,在...
京东商品爬虫淘宝店铺爬虫实战(selenium+python实现) .zip
1、Testng+selenium+Maven+WebDriver+Java+eclipse 实现禅道登录,百度搜索。 2、eclipse需安装Testng+selenium+Maven 3、下载对应版本的WebDriver驱动。Chrome驱动下载地址...
Python+Selenium+Unittest环境搭建详解 Python+Selenium+Unittest环境搭建是自动化测试中的一种重要组件,本文将详细介绍如何搭建Python+Selenium+Unittest环境,并解决在搭建过程中可能遇到的问题。 一、安装...
基于python flask vue-element-admin selenium 爬虫 后台资料齐全+详细文档+源码.zip 【备注】 1、该项目是个人高分项目源码,已获导师指导认可通过,答辩评审分达到95分 2、该资源内项目代码都经过测试运行成功,...
标题中的“Python-基于Selenium爬虫的自动每天点绿github主页的python脚本”指出,这个项目是使用Python编程语言,结合Selenium库来实现的一个自动化脚本。该脚本的主要目的是每天自动访问GitHub主页并执行某种操作...
基于Python3的动态网站爬虫,使用selenium+phantomjs实现爬取动态网站详细文档+资料齐全.zip 【备注】 1、该项目是个人高分项目源码,已获导师指导认可通过,答辩评审分达到95分 2、该资源内项目代码都经过测试运行...
使用selenium与webdriver打交道,是启动webdriver去调用浏览器,来完成操作。这就是selenium-chrome-driver-3.14.0.jar,作为chrome浏览器的webdriver,被selenium调用执行操作。