【问题标题】:Page not loading after proxy change using selenium python?使用 selenium python 更改代理后页面未加载?
【发布时间】: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/")

【问题讨论】:

    标签: python selenium proxy


    【解决方案1】:

    也许你需要加载一个特定的配置文件来添加路径

    fp = webdriver.FirefoxProfile(profilePath)
    

    目前正在为我指定配置文件路径和参数:

    ("network.proxy.type", 3)
    ("network.proxy.http", "localhost")
    ("network.proxy.http_port", 5555)
    

    【讨论】:

    • 我不想使用 localhost 而是使用不同的代理。我该怎么做?
    猜你喜欢
    • 2016-07-10
    • 2021-07-29
    • 1970-01-01
    • 1970-01-01
    • 2013-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-04
    相关资源
    最近更新 更多