【发布时间】: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