Last active
March 15, 2019 05:51
-
-
Save VSeryoga/15800719b5d8d8a0a8da24649a402b3c to your computer and use it in GitHub Desktop.
Использование прокси selenium python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
# proxy.zip -> background.js + manifest.json | |
=============================================================================== | |
# background.js | |
var config = { | |
mode: "fixed_servers", | |
rules: { | |
singleProxy: { | |
scheme: "http", | |
host: "YOU_PROXY_ADDRESS", | |
port: parseInt(YOUR_PROXY_PORT) | |
}, | |
bypassList: ["foobar.com"] | |
} | |
}; | |
chrome.proxy.settings.set({value: config, scope: "regular"}, function() {}); | |
function callbackFn(details) { | |
return { | |
authCredentials: { | |
username: "YOUR_PROXY_USERNAME", | |
password: "YOUR_PROXY_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" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment