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的更多相关文章

  1. selenium设置代理,基于chrome浏览器

    工作中遇到需要对项目中使用的selenium设置代理,跟大家分享一下. 1.下载chromeDriver:http://chromedriver.storage.googleapis.com/inde ...

  2. selenium 设置代理的话,可以使用这种方式,代码是我刚才测试过的,亲测可用

    from selenium import webdriver chrome_options = webdriver.ChromeOptions() chrome_options.add_argumen ...

  3. selenium 设置代理ip

    from selenium import webdriver options = webdriver.ChromeOptions() options.add_argument("--prox ...

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

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

  5. selenium设置Chrome浏览器不出现通知,设置代理IP

    from selenium import webdriver PROXY = "" chrome_options = webdriver.ChromeOptions() prefs ...

  6. selenium设置proxy、headers(phantomjs、Chrome、Firefox)

    phantomjs 设置ip 方法1: service_args = [ '--proxy=%s' % ip_html, # 代理 IP:prot (eg:192.168.0.28:808) '--p ...

  7. selenium设置chrome和phantomjs的请求头信息

    selenium设置chrome和phantomjs的请求头信息   出于反爬虫也好-跳转到手机端页面也好都需要设置请求头,那么如何进行呢? 目录 一:selenium设置phantomjs请求头: ...

  8. Selenium/HtmlUnit设置代理获取JS生成的网页

    通常我们使用Java提供的HttpURLConnection或者Apache的HttpClient获取的网页源代码都是直观可见的,其代码的内容和通过浏览器右键网页->点击查看网页源代码的内容一致 ...

  9. charles 设置为chrome代理

    本文参考:charles 设置为chrome代理 将charles设置为chrome的代理 需要注意的是,Chrome 和 Firefox 浏览器并不一定使用的就是本机,可能是一些代理工具,而 Cha ...

随机推荐

  1. angular基于ui-router实现系统权限控制

    前端去实现权限控制听起来有点扯淡(实际也有点扯淡),掩耳盗铃,主要是担心安全问题,但是如果在前后端分离的情况下,需要做一个带有权限控制的后台管理系统,angular基于ui-router应该怎么做呢? ...

  2. CSS响应式:根据分辨率加载不同CSS的几个方法,亲测可用

    有时候你需要把同一个页面在手机和pc同时打开,其中有一个办法就是判断不同分辨路加载不同的css 小编总结了几种分别加载css的方法: 1.比较复杂的使用js判断加载不同css (亲测可用) 但是这种方 ...

  3. Pig order by用法举例

    sorted = order data by $0;   数值类型按照数值大小比较 chararray类型按照字符的字典顺序比较 bytearray按照字节的字典顺序比较 复杂类型(map.tuple ...

  4. Selectivizr-让IE6~8支持CSS3伪类和属性选择器

    一.下载和demo 下载: 您可以狠狠地点击这里:selectivizr-1.0.0.zip(右键-[目标|链接另存为] 9.24K) demo: 您可以狠狠地点击这里:Selectivizr部分属性 ...

  5. 如何在 Azure 中均衡 Linux 虚拟机负载以创建高可用性应用程序

    负载均衡通过将传入请求分布到多个虚拟机来提供更高级别的可用性. 本教程介绍了 Azure 负载均衡器的不同组件,这些组件用于分发流量和提供高可用性. 你将学习如何执行以下操作: 创建 Azure 负载 ...

  6. Oracle EBS 附件功能

    SELECT fde.table_name, fde.data_object_code, fdet.user_entity_name, fdet.user_entity_prompt, fat.app ...

  7. 借助System.Linq.Dynamic, IQueryable根据排序字符串排序

    在使用Entity Framework时,若有多个排序,需要OrderBy (OrderByDescending)再ThenBy (ThenByDescending) 假设需要根据Name升序排序,再 ...

  8. 如何判断一个整数是否是2的N次幂

    static bool CheckPowerOfTwo(ulong num) { && (num & (num - )) == ; }

  9. Script:when transaction will finish rollback

    ------------------------------------------------------------------------------- -- -- Script: rollin ...

  10. 2. 跟踪标记 (Trace Flag) 3604, 3605 输出DBCC命令结果

    跟踪标记:3604 功能: 输出DBCC命令返回结果到查询窗口(通常是SSMS窗口),类似print命令的显示效果: 用途: 常用于获取DBCC IND, DBCC PAGE命令的输出结果,因为这2个 ...