1.1. 连接无用户名密码认证的代理

from selenium import webdriverchromeOptions = 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 Extensionargs:proxy_host (str): domain or ip address, ie proxy.domain.comproxy_port (int): portproxy_username (str): auth usernameproxy_password (str): auth passwordkwargs:scheme (str): proxy scheme, default httpplugin_path (str): absolute path of the extension       return str -> plugin_path"""import stringimport zipfileif 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_pathproxyauth_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

 

转载于:https://www.cnblogs.com/SunshineKimi/p/10589381.html

Selenium 设置代理chrome相关推荐

  1. pyppeteer使用阿布云代理隧道问题以及代码 和代理是否成功 python3 selenium设置代理ip的实现 IP 非真人甑别

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

  2. python 代理服务器 身份验证_如何使用Python+Selenium设置代理身份验证(用户和密码)...

    有一个Firefox+Python的例子,但是没有身份验证here.然后可以在源代码中找到其他可用参数here.所以看起来你需要以下几点:socksUsername socksPassword 例如: ...

  3. C# selenium设置具有账号密码的代理IP

    通常,我们给selenium设置代理的方式很简单,网上也有很多示例. 但是我们如何给selenium设置有账号密码验证的代理呢,在Selenium的SDK中并没有这个入口,也没有集成这几个参数. 于是 ...

  4. Python_各个代理网站/代理设置/代理池使用

    目录 一.常见的ip代理网站收集 二.代理池使用 1.崔大开源的代理池 2.jhao104开源的代理池 三.各个模块设置代理 1.requests设置代理ip 2.httpx设置代理ip 3.aioh ...

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

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

  6. Selenium Chrome设置代理之后验证依旧是本机ip原因

    网上流传的Selenium Chrome浏览器设置代理基本上是如下格式 from selenium import webdriver from selenium.webdriver.chrome.op ...

  7. java中selenium设置chrome浏览器为开发者模式与IP代理

    java中selenium设置chrome浏览器为开发者模式与IP代理 前言 代码 前言 之前为公司写了个爬虫项目,有时候为了绕过网站的反爬机制需要用到ip代理以及设置浏览器为开发者模式,看了一些se ...

  8. 模拟浏览器自动化测试工具Selenium之六设置代理篇

    在使用Selenium自动化测试时,如果需要设置代理访问网络时,可以参考如下代码: package com.test;import java.util.List; import org.openqa. ...

  9. webdriver+Chrome 设置代理

    from selenium import webdriver chromeOptions = webdriver.ChromeOptions()# 设置代理 chromeOptions.add_arg ...

最新文章

  1. python中的异常分类
  2. Xcode代码块功能
  3. JAVA中String类的intern()方法的作用
  4. 顶层 pom 中的 dependencies 与 dependencyManagement 区别
  5. flex 布局以及样式
  6. php curl keepalive,HTTPKeepAlive,开启还是关闭
  7. cf449D. Jzzhu and Numbers(容斥原理 高维前缀和)
  8. 基于点特征的各位姿求解算法对比(pose-estimation-compared)
  9. linux下查看某个文件或目录占用磁盘空间的大小
  10. update语句更新多条记录, 标记下
  11. 51单片机视频教程下载
  12. JavaScript 原生Ajax
  13. 干货:1分钟了解巨量引擎准入行业和资质规范
  14. ios获取本地音乐库音乐很详细
  15. 2015软件设计师考试(英语部分)
  16. loop与for loop分别实现乘法口诀表
  17. Saber 2016安装过程分享
  18. 史上最简单的软件破解——5行脚本代码完美破解99%的过期软件
  19. java Thread的介绍【电竞杜小帅】
  20. Shader学习七,UnityCG.cginc

热门文章

  1. 中国微商概念及产业链分析
  2. SDM660 xbl阶段使能I2C 设备实现
  3. 业务日志告警如何做?
  4. 疫情后的数字化转型:如何做好医疗数据治理
  5. 二---------
  6. 手动配置协议和服务器POP,在outlook上添加账户并介绍邮件协议相关知识
  7. (内含两种方式)Android 在线查看文档world丶xls丶ppt等文件
  8. 图片合成视频python
  9. windows10 配置 VNC server
  10. 脑肠轴必读综述 | 肠道菌群是如何影响人的情绪疾病呢?(一)