- Notifications
You must be signed in to change notification settings - Fork9
oxylabs/selenium-proxy-integration-python
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
For the integration to work, you'll need to installSelenium Wireto extend Selenium’s Python bindings as implementing proxiesthat require authentication using default Selenium modulecomplicates the process too much.
You can do it usingpip
command:
pip install selenium-wire
Another recommended package iswebdriver-manager
. It simplifies the managementof binary drivers for different browsers, so you don't need to manually downloada new version of a web driver after each update. Visit theofficial project directory on pypi tofind out more information.
You can install the following usingpip
as well:
pip install webdriver-manager
Required version of Python:Python 3.5
(or higher)
For proxies to work, you'll need to specify your account credentials insidethemain.py file.
USERNAME="your_username"PASSWORD="your_password"ENDPOINT="pr.oxylabs.io:7777"
Adjust theyour_username
andyour_password
value fields with the username and password ofyour Oxylabs account.
To see if the proxy is working, try visitingip.oxylabs.io/locationIf everything is working correctly, it will return an IP address of a proxy that you're using.
fromselenium.webdriver.common.byimportByfromseleniumwireimportwebdriver# A package to have a chromedriver always up-to-date.fromwebdriver_manager.chromeimportChromeDriverManagerUSERNAME="your_username"PASSWORD="your_password"ENDPOINT="pr.oxylabs.io:7777"defget_chrome_proxy(user:str,password:str,endpoint:str)->dict:wire_options= {"proxy": {"http":f"http://{user}:{password}@{endpoint}","https":f"http://{user}:{password}@{endpoint}", } }returnwire_optionsdefexecute_driver():options=webdriver.ChromeOptions()options.headless=Trueseleniumwire_options= {**get_chrome_proxy(USERNAME,PASSWORD,ENDPOINT),"driver_path":ChromeDriverManager().install(), }driver=webdriver.Chrome(options=options,seleniumwire_options=seleniumwire_options, )try:driver.get("https://ip.oxylabs.io/location")returnf'\nYour IP is:{driver.find_element(By.CSS_SELECTOR,"pre").text}'finally:driver.quit()if__name__=="__main__":print(execute_driver())
If you're having any trouble integrating proxies with Selenium and this guide didn't helpyou - feel free to contact Oxylabs customer support atsupport@oxylabs.io.
About
Tutorial for integrating Oxylabs' Residential Proxies with Selenium in Python
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors4
Uh oh!
There was an error while loading.Please reload this page.