user:pass proxies with selenium

2019-03-30 13:05发布

问题:

What is the best/easiest way to use user authenticated proxies in a program? I currently have this but I need username and password to be already filled in when browser opens.

from selenium import webdriver
PROXY = "123.123.123.243:80"

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--proxy-server=http://{}".format(PROXY))

print(chrome_options.arguments)
chrome = webdriver.Chrome(executable_path="drivers/chromedriver",chrome_options=chrome_options)
chrome.get("https://www.ipinfo.io")

回答1:

You can achieve the same using a Proxy Auto auth plugin

from selenium import webdriver

options = webdriver.ChromeOptions()
PROXY = "185.136.232.243:80"
options.add_extension("~/Downloads/Proxy Auto Auth.crx")
options.add_argument("--proxy-server=http://{}".format(PROXY))

driver = webdriver.Chrome(chrome_options=options)

driver.get("chrome-extension://ggmdpepbjljkkkdaklfihhngmmgmpggp/options.html")

driver.find_element_by_id("login").send_keys("user")
driver.find_element_by_id("password").send_keys("password")
driver.find_element_by_id("retry").clear()
driver.find_element_by_id("retry").send_keys("2")


driver.find_element_by_id("save").click()

driver.get("http://tarunlalwani.com")

Download the extension using below extensions

https://chrome.google.com/webstore/detail/get-crx/dijpllakibenlejkbajahncialkbdkjc/related https://chrome.google.com/webstore/detail/proxy-auto-auth/ggmdpepbjljkkkdaklfihhngmmgmpggp?utm_source=gmail