> [!WARNING]
> [Zyte API](../../zyte-api/get-started.md#zyte-api) is replacing Smart Proxy Manager. It is
> no longer possible to sign up to Smart Proxy Manager. If you are an
> existing Smart Proxy Manager user, see spm-migrate.

# Using Smart Proxy Manager with Selenium Wire

> [!WARNING]
> For the code below to work you must first [install the Zyte
> CA certificate](../../misc/ca.md#ca).

> [!NOTE]
> Selenium Wire requires [Selenium python libraries](https://www.selenium.dev/documentation/en/selenium_installation/installing_selenium_libraries/), [WebDriver](https://www.selenium.dev/documentation/en/selenium_installation/installing_webdriver_binaries/) installed and an active Smart Proxy Manager account. [Log in here](https://app.zyte.com/account/login).

> [!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](https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/#2-the-path-environment-variable) for Chrome.
2. Download and install [Zyte SmartProxy Selenium](https://github.com/zytedata/zyte-smartproxy-selenium):
   ```
   $ python3 -m pip install zyte-smartproxy-selenium
   ```
3. Save the following code as a `sample.py`:

```python
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 spm-headless.
2. Install [geckodriver](https://github.com/mozilla/geckodriver/releases) for Firefox.
3. Save the following code as a `sample.py`:

```python
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](https://github.com/wkeeling/selenium-wire#installation)
and run `sample.py` with:

```
$ pip install selenium-wire
$ python3 sample.py
```
