selenium proxy python chrome

Solutions on MaxInterview for selenium proxy python chrome by the best coders in the world

showing results for - "selenium proxy python chrome"
Gavin
22 Jul 2020
1proxyList = [
2    '192.168.1.1:8080',
3    '192.168.1.4:8080',
4    '192.168.1.9:8080'
5]
6chromeOptions = webdriver.ChromeOptions()
7chromeOptions.add_argument('--proxy-server={}'.format(random.choice(proxyList)))
8driver = webdriver.Chrome(executable_path="chromedriver.exe", chrome_options=chromeOptions)
9
Miley
23 Mar 2020
1def getPlugin(proxy_host, proxy_port, proxy_user, proxy_pass):
2    manifest_json = """
3    {
4        "version": "1.0.0",
5        "manifest_version": 2,
6        "name": "Chrome Proxy",
7        "permissions": [
8            "proxy",
9            "tabs",
10            "unlimitedStorage",
11            "storage",
12            "<all_urls>",
13            "webRequest",
14            "webRequestBlocking"
15        ],
16        "background": {
17            "scripts": ["background.js"]
18        },
19        "minimum_chrome_version":"22.0.0"
20    }
21    """
22 
23    background_js = """
24    var config = {
25            mode: "fixed_servers",
26            rules: {
27            singleProxy: {
28                scheme: "http",
29                host: "%s",
30                port: parseInt(%s)
31            },
32            bypassList: ["localhost"]
33            }
34        };
35 
36    chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
37 
38    function callbackFn(details) {
39        return {
40            authCredentials: {
41                username: "%s",
42                password: "%s"
43            }
44        };
45    }
46 
47    chrome.webRequest.onAuthRequired.addListener(
48                callbackFn,
49                {urls: ["<all_urls>"]},
50                ['blocking']
51    );
52    """ % (proxy_host, proxy_port, proxy_user, proxy_pass)
53    pluginfile = 'proxy_auth_plugin.zip'
54 
55    with zipfile.ZipFile(pluginfile, 'w') as zp:
56        zp.writestr("manifest.json", manifest_json)
57        zp.writestr("background.js", background_js)
58    
59    return pluginfile
60 
61 
62proxyArgsList = [
63                    {
64                        'proxy_host': '192.168.1.1',
65                        'proxy_port': '80',
66                        'proxy_user': 'abc',
67                        'proxy_pass': 'abcpassword',
68                    },
69                    {
70                        'proxy_host': '192.168.1.2',
71                        'proxy_port': '80',
72                        'proxy_user': 'abc',
73                        'proxy_pass': 'abcpassword',
74                    },
75                    'proxy_host': '192.168.1.3',
76                        'proxy_port': '80',
77                        'proxy_user': 'abc',
78                        'proxy_pass': 'abcpassword',
79                    
80                ]
81 
82chromeOptions = webdriver.ChromeOptions()
83chromeOptions.add_extension(getPlugin(**random.choice(proxyArgsList)))
84driver = webdriver.Chrome(executable_path="chromedriver.exe", chrome_options=chromeOptions)
85