Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

proxy selenium python

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

options = Options()
options.add_argument("--proxy-server={}".format("127.0.0.1:12345"))
driver = webdriver.Chrome(executable_path="webdriver.exe", options=options)
Comment

adding proxy in selenium python

# Proxies for Selenium (Python)
PROXY_HOST = '52.206.93.181'  # rotating proxy or host
PROXY_PORT = 31112 # port
PROXY_USER = 'username' # username
PROXY_PASS = 'password' # password

chromePath = 'chromedriver.exe' # chrome driver path


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 = """
var config = {
        mode: "fixed_servers",
        rules: {
        singleProxy: {
            scheme: "http",
            host: "%s",
            port: parseInt(%s)
        },
        bypassList: ["localhost"]
        }
    };

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

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

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



def botInitialization(use_proxy=True, user_agent=None):
    path = os.path.dirname(os.path.abspath(__file__))
    chrome_options = webdriver.ChromeOptions()
    if use_proxy:
        pluginfile = 'proxy_auth_plugin.zip'

        with zipfile.ZipFile(pluginfile, 'w') as zp:
            zp.writestr("manifest.json", manifest_json)
            zp.writestr("background.js", background_js)
        chrome_options.add_extension(pluginfile)
    if user_agent:
        chrome_options.add_argument('--user-agent=%s' % user_agent)
    driver = webdriver.Chrome(
        os.path.join(chromePath),
        chrome_options=chrome_options)
    driver.maximize_window()
    return driver



driver = botInitialization()
driver.get("https://www.google.com/")
Comment

PREVIOUS NEXT
Code Example
Python :: python make string one line 
Python :: handle 404 in requests python 
Python :: new dataframe based on certain row conditions 
Python :: Game of Piles Version 2 codechef solution 
Python :: how to make exe from.py file 
Python :: selenium webdriver scroll down python 
Python :: python loop back to start 
Python :: python append value to dictionary list 
Python :: seaborn iris dataset 
Python :: How to append train and Test dataset in python 
Python :: print python float precision 
Python :: string format zero padded int python 
Python :: sorting a list of dictionaries 
Python :: jsonschema in python 
Python :: gspread_pandas pypi 
Python :: python string format 
Python :: declare pandas dataframe with values 
Python :: pd df rename 
Python :: python read values from file 
Python :: python detect warning 
Python :: if else in list comprehension 
Python :: enumerate string pythonm 
Python :: Python get all keys from nested dictionary 
Python :: save turtle programming python 
Python :: search in dict python 
Python :: django superuser 
Python :: planet 
Python :: setattr python 
Python :: how to write variables in python 
Python :: creating new column with dictionary 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =