Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.10 KB | None | 0 0
  1. import os
  2. import zipfile
  3.  
  4. from selenium import webdriver
  5.  
  6. PROXY_HOST = 'sk21.nordvpn.com'  # rotating proxy
  7. PROXY_PORT = 80
  8. PROXY_USER = 'kvintus'
  9. PROXY_PASS = 'mfbsitSoIaFetb46'
  10.  
  11.  
  12. manifest_json = """
  13. {
  14.    "version": "1.0.0",
  15.    "manifest_version": 2,
  16.    "name": "Chrome Proxy",
  17.    "permissions": [
  18.        "proxy",
  19.        "tabs",
  20.        "unlimitedStorage",
  21.        "storage",
  22.        "<all_urls>",
  23.        "webRequest",
  24.        "webRequestBlocking"
  25.    ],
  26.    "background": {
  27.        "scripts": ["background.js"]
  28.    },
  29.    "minimum_chrome_version":"22.0.0"
  30. }
  31. """
  32.  
  33. background_js = """
  34. var config = {
  35.        mode: "fixed_servers",
  36.        rules: {
  37.          singleProxy: {
  38.            scheme: "http",
  39.            host: "%s",
  40.            port: parseInt(%s)
  41.          },
  42.          bypassList: ["localhost"]
  43.        }
  44.      };
  45.  
  46. chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
  47.  
  48. function callbackFn(details) {
  49.    return {
  50.        authCredentials: {
  51.            username: "%s",
  52.            password: "%s"
  53.        }
  54.    };
  55. }
  56.  
  57. chrome.webRequest.onAuthRequired.addListener(
  58.            callbackFn,
  59.            {urls: ["<all_urls>"]},
  60.            ['blocking']
  61. );
  62. """ % (PROXY_HOST, PROXY_PORT, PROXY_USER, PROXY_PASS)
  63.  
  64.  
  65. def get_chromedriver(use_proxy=False, user_agent=None):
  66.     path = os.path.dirname(os.path.abspath(__file__))
  67.     chrome_options = webdriver.ChromeOptions()
  68.     if use_proxy:
  69.         pluginfile = 'proxy_auth_plugin.zip'
  70.  
  71.         with zipfile.ZipFile(pluginfile, 'w') as zp:
  72.             zp.writestr("manifest.json", manifest_json)
  73.             zp.writestr("background.js", background_js)
  74.         chrome_options.add_extension(pluginfile)
  75.     if user_agent:
  76.         chrome_options.add_argument('--user-agent=%s' % user_agent)
  77.    
  78.     driver = webdriver.Chrome(chrome_options=chrome_options)
  79.     return driver
  80.  
  81. def main():
  82.     driver = get_chromedriver(use_proxy=True)
  83.     #driver.get('https://www.google.com/search?q=my+ip+address')
  84.     driver.get('https://ifconfig.co/ip')    
  85.     print(driver.page_source)
  86.    
  87. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement