user:使用selenium传递代理

时间:2017-09-20 19:23:11

标签: python selenium selenium-webdriver webdriver selenium3

在程序中使用用户身份验证代理的最佳/最简单方法是什么?我目前有这个,但我需要在浏览器打开时填写用户名和密码。

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")

2 个答案:

答案 0 :(得分:7)

您可以使用Proxy Auto auth插件

实现相同目的
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")

使用以下扩展名下载扩展程序

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

答案 1 :(得分:0)

我成功地将代理自动身份验证与头部chrome一起使用,但是无头chrome失败了。

selenium.common.exceptions.WebDriverException:消息:未知错误:无法等待扩展程序后台页面的加载:chrome-extension://ggmdpepbjljkkkdaklfihhngmmgmpmpp/_genic_background_page.html 来自未知错误:无法找到页面:chrome-extension://ggmdpepbjljkkkdaklfihhngmmgmpggp/_genic_background_page.html

相关问题