Last active
August 22, 2021 21:09
-
-
Save benastahl/1c7368b3a4d98544ff27f07e4a8f89cb to your computer and use it in GitHub Desktop.
use a proxy in your selenium instance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver.chrome.options import Options | |
import time | |
proxy = '208.207.224.119:1337:tfzyxgq:lhr2y' | |
(IPv4, Port, username, password) = proxy.split(':') | |
ip = IPv4 + ':' + Port | |
proxy_options = { | |
"proxy": { | |
"http": "http://" + username + ":" + password + "@" + ip, | |
"https": "http://" + username + ":" + password + "@" + ip, | |
} | |
} | |
def arguments(): | |
chrome_opts = Options() | |
chrome_opts.add_argument("--proxy-server=%s" % proxy) | |
return chrome_opts | |
web_driver = webdriver.Chrome(options=arguments(), executable_path="chromedriver.exe", selenium_options=proxy_options) | |
web_driver.get("https://whatismyipaddress.com/") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment