如何在没有Polipo的情况下将Crawlera与硒(Python,Chrome,Windows)一起使用

How to use Crawlera with selenium (Python, Chrome, Windows) without Polipo

所以基本上我正在尝试在使用python的Windows上使用来自scrapinghub和硒铬的Crawlera代理。

我检查了文档,他们建议像这样使用Polipo:

1)将以下行添加到/ etc / polipo / config

1
2
parentProxy ="proxy.crawlera.com:8010"
parentAuthCredentials ="<CRAWLERA_APIKEY>:"

2)将其添加到硒驱动器中

1
2
3
4
5
6
7
8
9
10
11
12
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变量并将其更改为爬虫?每次我尝试执行此操作时,它都不会考虑在内,并且无需代理即可运行。

爬虫代理格式如下:[API KEY]:@ [HOST]:[PORT]

我尝试使用以下行添加代理:

1
chrome_options.add_argument('--proxy-server=http://[API KEY]:@[HOST]:[PORT])

但是问题是我需要以不同的方式指定HTTP和HTTPS。

提前谢谢!


Polipo不再被维护,因此在使用中存在挑战。 Crawlera需要身份验证,Chrome驱动程序目前似乎不支持该身份验证。您可以尝试使用Firefox WebDriver,因为您可以在自定义Firefox配置文件中设置代理身份验证,并使用在代理服务器后面运行硒和http://toolsqa.com/selenium-webdriver/http-proxy-身份验证/。

我一直在遇到同样的问题,并从中得到了一些缓解。希望它也会对您有帮助。要解决此问题,您必须使用Firefox驱动程序及其配置文件以这种方式放置代理信息。

1
2
3
4
5
6
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)

这完全对我有用。作为参考,您可以使用上述站点。