Using Smart Proxy Manager with Selenium

Note

Selenium requires language-specific libraries, WebDriver installed and an active Smart Proxy Manager account. Log in or signup here.

Python integration

Save the following code as a sample_script.py:

from selenium import webdriver

headless_proxy = "localhost:3128"
proxy = {
    "proxyType": "manual",
    "httpProxy": headless_proxy,
    "ftpProxy": headless_proxy,
    "sslProxy": headless_proxy,
    "noProxy": "",
}

options = webdriver.ChromeOptions()
options.add_argument("--ignore-certificate-errors")
options.set_capability("proxy", proxy)
browser = webdriver.Chrome(options=options)
browser.get("https://toscrape.com")
browser.save_screenshot("screenshot.png")
browser.close()

Run sample_script.py with:

$ python3 sample_script.py

Javascript integration

Save the following code as a sample_script.js:

const webdriver = require("selenium-webdriver");
const chrome = require('selenium-webdriver/chrome');
const proxy = require('selenium-webdriver/proxy');
const fs = require('fs').promises

const headlessProxyHost = "localhost:3128";

async function main(){
    var options = await new chrome.Options();
    await options.addArguments("--ignore-certificate-errors")

    let browser = await new webdriver.Builder()
        .forBrowser('chrome')
        .setProxy(proxy.manual({http: headlessProxyHost, https: headlessProxyHost}))
        .setChromeOptions(options)
        .build();

    url = "https://toscrape.com";

    await browser.get(url);
    console.log(await browser.getPageSource())
    let image = await browser.takeScreenshot()
    await fs.writeFile('screenshot.png', image, 'base64');
    await browser.quit();
}

main()

Run sample_script.js with:

$ node sample_script.js

Java integration

A sample Java class:

import org.openqa.selenium.*;
import org.openqa.selenium.chrome.*;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;

public class SPMTest {

    public static void main(String[] args) throws InterruptedException, IOException {

        String headlessProxyHost = "localhost:3128";

        ChromeOptions options = new ChromeOptions();
        options.addArguments("--ignore-certificate-errors");

        Proxy proxy = new Proxy();
        proxy.setHttpProxy(headlessProxyHost);
        proxy.setSslProxy(headlessProxyHost);
        options.setCapability("proxy", proxy);

        WebDriver browser = new ChromeDriver(options);

        String url = "https://toscrape.com";

        browser.get(url);
        System.out.println(browser.getPageSource());
        File image = ((TakesScreenshot) browser).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(image, new File("screenshot.png"));
        browser.quit();
    }
}