Using Smart Proxy Manager with Selenium Wire

Warning

zyte-smartproxy-ca.crt should be installed in your OS for the below code to work. You can follow these instructions in order to install it.

Note

Selenium Wire requires Selenium python libraries, WebDriver installed and an active Smart Proxy Manager account. Log in or signup here.

Note

All the code in this documentation has been tested with Geckodriver 0.30.0, Python 3.9.5 and selenium-wire 4.5.4.

Option 1 - Zyte SmartProxy Selenium

  1. Install ChromeDriver for Chrome.

  2. Download and install Zyte SmartProxy Selenium:

    $ python3 -m pip install zyte-smartproxy-selenium
    
  3. Save the following code as a sample.py:

from zyte_smartproxy_selenium import webdriver

browser = webdriver.Chrome(spm_options={'spm_apikey': '<Smart Proxy Manager API KEY>'})
browser.get('https://toscrape.com')
browser.save_screenshot('screenshot.png')
browser.close()
  1. Run sample.py with:

    $ python3 sample.py
    

Option 2 - Zyte SmartProxy Headless Proxy

  1. Setup the Zyte SmartProxy (formerly Crawlera) Headless Proxy as described in Using Headless Browsers with Zyte Smart Proxy Manager.

  2. Install geckodriver for Firefox.

  3. Save the following code as a sample.py:

from seleniumwire import webdriver

headless_proxy = "http://127.0.0.1:3128"
seleniumwire_options = {
    "proxy": {"http": headless_proxy, "https": headless_proxy, "no_proxy": ""}
}
browser = webdriver.Firefox(seleniumwire_options=seleniumwire_options)
browser.get("https://toscrape.com")
browser.save_screenshot("screenshot.png")
browser.close()

4. Install Selenium Wire and run sample.py with:

$ pip install selenium-wire
$ python3 sample.py