码迷,mamicode.com
首页 > 其他好文 > 详细

selenium + chromeDriver的ip代理设置

时间:2019-03-20 17:33:03      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:xxxxxx   ati   conf   9.1   miss   function   ext   required   man   

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import zipfile

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"
}
"""

#配置   host和port
#authCredentials 不知道怎么做,没配置也能用

background_js = """
var config = {
        mode: "fixed_servers",
        rules: {
          singleProxy: {
            scheme: "http",
            host: "39.137.69.6",   
            port: parseInt(8080)
          },
          bypassList: ["foobar.com"]
        }
      };


chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});

function callbackFn(details) {
    return {
        authCredentials: {
            username: "XXXXXXXXX",
            password: "XXXXXXXXX"
        }
    };
}

chrome.webRequest.onAuthRequired.addListener(
            callbackFn,
            {urls: ["<all_urls>"]},
            ['blocking']
);
"""

pluginfile = 'proxy_auth_plugin.zip'

with zipfile.ZipFile(pluginfile, 'w') as zp:
    zp.writestr("manifest.json", manifest_json)
    zp.writestr("background.js", background_js)

co = Options()
co.add_argument("--start-maximized")
co.add_extension(pluginfile)

driver = webdriver.Chrome(chrome_options=co)
driver.get("http://ip138.com/")

ip代理地址网站

展示ip代理是否设置成功

stack overflow原文

selenium + chromeDriver的ip代理设置

标签:xxxxxx   ati   conf   9.1   miss   function   ext   required   man   

原文地址:https://www.cnblogs.com/panfengde/p/10565982.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!