【发布时间】:2019-01-24 09:19:44
【问题描述】:
我希望我今天能找到你。
背景信息: 今天我正在编写一个程序并想添加代理支持。到目前为止,我已经设法使用 Localhost 进行连接。但是,我想添加对具有用户名和密码(格式为 IP 地址:端口:用户名:密码)的代理的支持,以便创建尽可能多的帐户。到目前为止我使用的代码是:
from selenium import webdriver
PROXY_HOST = "107.178.214.243"
PROXY_PORT = "3128"
USERNAME = "test"
PASSWORD = "test"
profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", PROXY_HOST)
profile.set_preference("network.proxy.http_port", PROXY_PORT)
profile.set_preference("network.proxy.socks_username", USERNAME)
profile.set_preference("network.proxy.socks_password", PASSWORD)
profile.update_preferences()
# executable_path = define the path if u don't already have in the PATH
system variable.
browser = webdriver.Firefox(firefox_profile=profile)
browser.get('https://whatismyipaddress.com/')
browser.maximize_window()
现在这仅适用于 1 个代理,它不是无头的(我知道)。我想看看在我让它无头之前发生了什么。
会发生什么:它可以很好地打开 Firefox 浏览器并访问该站点。但是它实际上并不使用代理。它只使用我的本地主机。
我需要什么:我需要它来使用代理。还希望它能够从文本文件中获取代理并使用它们
【问题讨论】:
-
感谢您的帮助。但是浏览该帖子,在我看来,他们没有为经过身份验证的代理(具有用户名和密码的代理)提供解决方案