我想在我的docker selenium容器中使用带有用户名和密码的代理。
我尝试了我发现的所有解决方案,但它不起作用。我试过http proxy:
capabilities = DesiredCapabilities.FIREFOX
capabilities['proxy'] = {
'proxyType': 'MANUAL',
'httpProxy': f'{proxy.ip_address}:{proxy.port}',
'sslProxy': 'ip:port',
'socksUsername': proxy.login,
'socksPassword': proxy.password
}
browser = webdriver.Remote(command_executor='http://hub:4444/wd/hub',
desired_capabilities=capabilities,
browser_profile=profile)
selenium.common.exceptions.InvalidArgumentException:消息:无效 代理配置条目:socksPassword
试过袜子代理:
proxy = Proxy({
'proxyType': ProxyType.MANUAL,
'socksProxy': f'{proxy.ip_address}:{proxy.port}',
'socksUsername': proxy.login,
'socksPassword': proxy.password
})
browser = webdriver.Remote(command_executor='http://hub:4444/wd/hub',
desired_capabilities=capabilities,
browser_profile=profile,
proxy=proxy)
消息:无效的代理配置条目:socksPassword
我还尝试通过firefox配置文件设置代理,例如here,但它似乎无法正常工作,因为没有为代理设置密码的选项。
代理正在运行,因为当我请求时:
proxy = 'socks5://username:password@ip:port' resp = requests.get('https://api.ipify.org?format=json',
proxies=dict(http=proxy,
https=proxy)) print(resp.json())
返回正确的结果
答案 0 :(得分:0)
唯一的解决方案是使用没有密码的代理
答案 1 :(得分:0)
Python3。您需要pip3安装geckodriver
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.proxy import Proxy, ProxyType
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
# https://free-proxy-list.net/
proxy = '78.96.125.24:3128'
firefox_capabilities['proxy'] = {
"proxyType": "MANUAL",
"httpProxy": proxy,
"ftpProxy": proxy,
"sslProxy": proxy,
}
browser = webdriver.Firefox(capabilities=firefox_capabilities)
browser.get('https://httpbin.org/ip')
# browser.get('https://www.google.pl')