Selenium Proxy Integration with Bright Data

Alexander Kachar
Alexander Kachar
  • Updated

Learn how to set up your Selenium proxy settings and integrate them with Bright Data's Proxy IPs

Selenium is an advanced browser automation software used to simulate browsing environments for the most accurate website testing and more

Bright Data Super Proxy and Selenium Integration

  • Begin by going to your Bright Data Dashboard and clicking ‘create a Zone’.
  • Choose ‘Network type’ and click save.
  • Within Selenium fill in the ‘Proxy IP:Port’ in the ‘setProxy’ function for examplezproxy.lum-superproxy.io:22225 of both http and https.
  • Under ‘sendKeys’ input your Bright Data account ID and proxy Zone name:lum-customer-CUSTOMER-zone-YOURZONE and your Zone password found in the Zone settings.
  • JavaScript example:
const {Builder, By, Key, until} = require('selenium-webdriver');
const proxy = require('selenium-webdriver/proxy');

(async function example(){
  let driver = await new Builder().forBrowser('firefox').setProxy(proxy.manual({
    http: 'zproxy.lum-superproxy.io:22225',
    https: 'zproxy.lum-superproxy.io:22225'
  })).build()

  try {
    await driver.get('http://lumtest.com/myip.json');
    driver.switchTo().alert()
      .sendKeys('lum-customer-USERNAME-zone-YOURZONE'+Key.TAB+'PASSWORD');
    driver.switchTo().alert().accept();
  } finally {
      await driver.quit();
  }
})();
  • Python example (deprecated, recommend using with Proxy Manager, next section):
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
from seleniumwire import webdriver
import time

PATH = "/path/to/chromedriver.exe" #Path to chromedriver (Adjust as needed)

options = {
'proxy': {'http': 'http://lum-customer-CUST_ID-zone-ZONE_NAME:PASSWORD@zproxy.lum-superproxy.io:22225',
'https': 'http://lum-customer-CUST_ID-zone-ZONE_NAME:PASSWORD@zproxy.lum-superproxy.io:22225'},
}

chrome = webdriver.Chrome(PATH, seleniumwire_options=options)
If need to add headers to request
chrome.header_overrides = {

}
chrome.get("https://lumtest.com/myip.json")

print(chrome.execute_script('return document.body.innerHTML;')) #print page html
time.sleep(5) #close after 5 seconds

chrome.quit()

Proxy Manager and Selenium Integration

  • Create a Zone with the network, IP type and number of IPs you wish to use.
  • Install the Bright Data Proxy Manager.
  • Click ‘add new proxy’ and choose the Zone and settings you require, click ‘save’.
  • In Selenium under the setProxy input your local IP and proxy manager port (i.e. 127.0.0.1:24000)
    • The local host IP is 127.0.0.1
    • The port created in the Proxy Manager is 24XXX, for example 24000
  • Leave the username and password field empty, as the Bright Data Proxy Manager has already been authenticated with the Super Proxy.
  • JavaScript example:
const {Builder, By, Key, until} = require('selenium-webdriver');
const proxy = require('selenium-webdriver/proxy');

(async function example(){
    let driver = await new Builder().forBrowser('firefox').setProxy(proxy.manual({
        http: '127.0.0.1:24000',
        https: '127.0.0.1:24000'
    })).build()

    try {
        await driver.get('http://lumtest.com/myip.json');
        driver.switchTo().alert().accept();
    } finally {
        await driver.quit();
    }
})();
  • Python example:
import random
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

PROXY = "127.0.0.1:24000"
PATH = "/path/to/chromedriver.exe" #Path to chromedriver (Adjust as needed)

print(PROXY)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % PROXY)

chrome = webdriver.Chrome(PATH, options=chrome_options)
If need to add headers to request
chrome.header_overrides = {

}
chrome.get("https://lumtest.com/myip.json")

print(chrome.execute_script('return document.body.innerHTML;')) #print page html
time.sleep(5) #close after 5 seconds
Share this

Was this article helpful?

1 out of 3 found this helpful