所以基本上我正在尝试使用python在Windows上使用selenium chrome从scrapinghub中使用Crawlera Proxy。
我检查了文档,他们建议像这样使用Polipo:
1)将以下行添加到/ etc / polipo / config
parentProxy = "proxy.crawlera.com:8010"
parentAuthCredentials = "<CRAWLERA_APIKEY>:"
2)将其添加到硒驱动程序
polipo_proxy = "127.0.0.1:8123"
proxy = Proxy({
'proxyType': ProxyType.MANUAL,
'httpProxy': polipo_proxy,
'ftpProxy' : polipo_proxy,
'sslProxy' : polipo_proxy,
'noProxy' : ''
})
capabilities = dict(DesiredCapabilities.CHROME)
proxy.add_to_capabilities(capabilities)
driver = webdriver.Chrome(desired_capabilities=capabilities)
现在我不想使用Polipo并直接使用代理。
有没有办法替换polipo_proxy变量并将其更改为crawlera变量?每次我尝试这样做时,它都没有考虑到它并且没有代理运行。
Crawlera代理格式如下:[API KEY]:@ [HOST]:[PORT]
我尝试使用以下行添加代理:
chrome_options.add_argument('--proxy-server=http://[API KEY]:@[HOST]:[PORT])
但问题是我需要以不同方式指定HTTP和HTTPS。
提前谢谢!
答案 0 :(得分:1)
Polipo不再得到维护,因此在使用中存在挑战。 Crawlera需要验证,Chrome驱动程序目前似乎不支持该验证。您可以尝试使用Firefox Webdriver,因为您可以在自定义Firefox配置文件中设置代理身份验证,并使用Running selenium behind a proxy server和http://toolsqa.com/selenium-webdriver/http-proxy-authentication/中所示的配置文件。
我一直在遇到同样的问题,并从中得到了一些缓解。希望它也会对您有帮助。要解决此问题,您必须使用Firefox驱动程序及其配置文件以这种方式放置代理信息。
profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", "proxy.server.address")
profile.set_preference("network.proxy.http_port", "port_number")
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile=profile)
这完全对我有用。作为参考,您可以使用上述网站。
答案 1 :(得分:0)
Scrapinghub 创建一个新项目。需要使用apikey设置转发代理,然后设置webdriver使用这个代理。项目地址为:zyte-smartproxy-headless-proxy
你可以看看