|
1 | | -# selenium-proxy-integration |
| 1 | +# Oxylabs’ Residential Proxies integration with Selenium |
| 2 | + |
| 3 | +[<img src="https://img.shields.io/static/v1?label=&message=Python&color=brightgreen" />](https://github.com/topics/python) [<img src="https://img.shields.io/static/v1?label=&message=Selenium&color=orange" />](https://github.com/topics/selenium) [<img src="https://img.shields.io/static/v1?label=&message=Web-Scraping&color=yellow" />](https://github.com/topics/web-scraping) [<img src="https://img.shields.io/static/v1?label=&message=Rotating%20Proxies&color=blueviolet" />](https://github.com/topics/rotating-proxies) |
| 4 | + |
| 5 | +## Requirements |
| 6 | +For the integration to work, you'll need to install Selenium on your system. You can do it using `pip` command: |
| 7 | +```bash |
| 8 | +pip install selenium |
| 9 | +``` |
| 10 | +Another required package is `webdriver-manager`. It's a package that simplifies the management of binary drivers for different browsers, so you don't need to manually download a new version of a web driver after each update. Visit the [official project directory](https://pypi.org/project/webdriver-manager/) on pypi to find out more information. You can install the following using `pip` as well. |
| 11 | +```bash |
| 12 | +pip install webdriver-manager |
| 13 | +``` |
| 14 | +Required version of Python: `Python 3.5` (or higher) |
| 15 | +## Proxy Authentication |
| 16 | +For proxies to work, you'll need to specify your account credentials inside the [main.py](https://github.com/oxylabs/selenium-proxy-integration/blob/main/main.py) file. |
| 17 | +```python |
| 18 | +USERNAME = "your_username" |
| 19 | +PASSWORD = "your_password" |
| 20 | +HOST = "pr.oxylabs.io" |
| 21 | +PORT = 7777 |
| 22 | +``` |
| 23 | +Adjust the `your_username` and `your_password` fields with the username and password of your Oxylabs account. |
| 24 | +## Country-Specific Entry Node |
| 25 | +If you want, you can also specify the entry node of a specific country: |
| 26 | +```python |
| 27 | +COUNTRY = "US" |
| 28 | +``` |
| 29 | +To do that, adjust the `country` variable to any country that Oxylabs support. You can check out our [documentation](https://developers.oxylabs.io/residential-proxies/#country-specific-entry-nodes) for a complete list of country-specific entry nodes. |
| 30 | + |
| 31 | +## Testing Proxy Connection |
| 32 | +You can test proxy connection by visiting https://ip.oxylabs.io/. It will return your current IP address. |
| 33 | +```python |
| 34 | +try: |
| 35 | + driver.get("https://ip.oxylabs.io/") |
| 36 | + time.sleep(5) |
| 37 | +finally: |
| 38 | + driver.close() |
| 39 | +``` |
| 40 | + |
| 41 | +## Full Code |
| 42 | +```python |
| 43 | + |
| 44 | +import time |
| 45 | +from selenium import webdriver |
| 46 | +from webdriver_manager.chrome import ChromeDriverManager |
| 47 | +from proxies import chrome_proxy |
| 48 | + |
| 49 | +USERNAME = "your_username" |
| 50 | +PASSWORD = "your_password" |
| 51 | +HOST = "pr.oxylabs.io" |
| 52 | +PORT = 7777 |
| 53 | +COUNTRY = "US" |
| 54 | + |
| 55 | +options = webdriver.ChromeOptions() |
| 56 | +proxy_ext = chrome_proxy(USERNAME, PASSWORD, HOST, PORT, COUNTRY) |
| 57 | +options.add_extension(proxy_ext) |
| 58 | +driver = webdriver.Chrome(ChromeDriverManager().install(), options=options) |
| 59 | + |
| 60 | +try: |
| 61 | + driver.get("https://ip.oxylabs.io/") |
| 62 | + time.sleep(5) |
| 63 | +finally: |
| 64 | + driver.close() |
| 65 | +``` |
| 66 | +If you're having any trouble integrating proxies with Selenium and this guide didn't help you - feel free to contact Oxylabs customer support at support@oxylabs.io. |
| 67 | + |
| 68 | + |
0 commit comments