【发布时间】:2019-07-16 09:10:19
【问题描述】:
我正在尝试在 python 中使用 selenium 驱动程序更改我的代理。但是当我改变它时,页面没有加载。我尝试了几个IP,但没有一个有效。 我也增加了页面超时,但仍然无法访问该站点。
from selenium import webdriver
#ip address that I got from https://free-proxy-list.net/
ProxyHost = "110.34.39.58"
ProxyPort = "8080"
def ChangeProxy(PROXY_HOST, PROXY_PORT):
fp = webdriver.FirefoxProfile()
print
PROXY_PORT
print
PROXY_HOST
fp.set_preference("network.proxy.type", 1)
fp.set_preference("network.proxy.http", PROXY_HOST)
fp.set_preference("network.proxy.http_port", int(PROXY_PORT))
fp.set_preference("network.proxy.https", PROXY_HOST)
fp.set_preference("network.proxy.https_port", int(PROXY_PORT))
fp.set_preference("network.proxy.ssl", PROXY_HOST)
fp.set_preference("network.proxy.ssl_port", int(PROXY_PORT))
fp.set_preference("network.proxy.ftp", PROXY_HOST)
fp.set_preference("network.proxy.ftp_port", int(PROXY_PORT))
fp.set_preference("network.proxy.socks", PROXY_HOST)
fp.set_preference("network.proxy.socks_port", int(PROXY_PORT)))
fp.update_preferences()
return webdriver.Firefox(executable_path=
r'C:\webdriver\geckodriver.exe',firefox_profile=fp)
driver=ChangeProxy(ProxyHost, ProxyPort)
driver.get("https://www.whatismyip.com/")
【问题讨论】: