问题
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
回答2:
I used Proxy Auto Auth with head chrome successfully,but headless chrome is fail。
selenium.common.exceptions.WebDriverException: Message: unknown error: failed to wait for extension background page to load: chrome-extension://ggmdpepbjljkkkdaklfihhngmmgmpggp/_generated_background_page.html from unknown error: page could not be found: chrome-extension://ggmdpepbjljkkkdaklfihhngmmgmpggp/_generated_background_page.html
来源:https://stackoverflow.com/questions/46330245/userpass-proxies-with-selenium