zoukankan      html  css  js  c++  java
  • chromedriver 代理设置(账号密码)

    在使用selenium时遇到的一个问题 如何为chromedriver设置有密码的代理 在借鉴了stackoverflow上的答案

    background.js

    var config = {
        mode: "fixed_servers",
        rules: {
          singleProxy: {
            scheme: "http",
            host: "你的ip",
            port: parseInt(端口)
          },
          bypassList: ["foobar.com"]
        }
      };
    
    chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
    
    function callbackFn(details) {
        return {
            authCredentials: {
                username: "用户名",
                password: "密码"
            }
        };
    }
    
    chrome.webRequest.onAuthRequired.addListener(
            callbackFn,
            {urls: ["<all_urls>"]},
            ['blocking']
    );
    

    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中替换为代理信息 manifest.json不变 然后打包成proxy.zip既可

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    chrome_options = Options()
    chrome_options.add_extension("proxy.zip")
    
    driver = webdriver.Chrome(executable_path='chromedriver.exe', chrome_options=chrome_options)
    driver.get("http://google.com")
    driver.close()
    
    

  • 相关阅读:
    vue router replace
    html transition 标签
    transformorigin
    动态设置class名称
    oracle中trim,ltrim,rtrim函数用法
    blob字段存储文件并读取
    分区表的本地索引竟然失效了——ORA01502
    powerdesigner使用细节
    PLS00231错误:function name may not be used in SQL
    sqlplus命令说明
  • 原文地址:https://www.cnblogs.com/tongchengbin/p/8477676.html
Copyright © 2011-2022 走看看