Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Tutorial for integrating Oxylabs' Residential Proxies with Selenium in Python

NotificationsYou must be signed in to change notification settings

oxylabs/selenium-proxy-integration-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 

Repository files navigation

Oxylabs promo code

Requirements

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)

Proxy Authentication

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.

Testing Proxy Connection

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.

Full Code

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.


[8]ページ先頭

©2009-2025 Movatter.jp