【问题标题】:Rotate server IPs using selenium (Python)使用 selenium (Python) 轮换服务器 IP
【发布时间】:2017-10-11 12:41:11
【问题描述】:

我正在做一个项目,我需要使用 selenium 报废一些数据。为了报废,我想轮换我的服务器 IP(我的服务器有多个 IP 连接到单台机器)。对于每个请求,我想使用不同的 IP,这样我就不会被阻止。不确定如何做到这一点。我在 ubuntu 16.04 上使用 Firefox。

到目前为止,通过谷歌搜索了几个小时,我发现了这个,但它不起作用。

profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", 'my-ip')
profile.set_preference("network.proxy.http_port", 80)
profile.set_preference("network.proxy.https", 'my-ip')
profile.set_preference("network.proxy.https_port", 80)
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile=profile)
driver.get('https://api.ipify.org/')
print driver.page_source

我正在使用https://api.ipify.org/ 进行测试,只是为了找出生成的请求使用了哪个 IP,但它总是向我显示我的服务器的主 IP,即使我使用上面的代码设置了不同的 IP。

任何帮助/指导或解决方法将不胜感激。

【问题讨论】:

    标签: python selenium firefox web-scraping


    【解决方案1】:

    您需要将 Firefox 绑定到不同的网络接口,这是不可能的。

    一种解决方法是在您的服务器上设置一个类似squid 的代理,将其配置为根据您可以从 Firefox 的 selenium 配置中控制的参数,通过每个接口路由传出流量,例如代理端口(它应该可以使用 squid acl)。

    【讨论】:

    • 谢谢,我试试squid
    猜你喜欢
    • 1970-01-01
    • 2021-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-06
    • 1970-01-01
    • 2021-07-31
    • 1970-01-01
    相关资源
    最近更新 更多