简体   繁体   English

python selenium-使用phantomJS代理

[英]python selenium - using phantomJS proxy

I am trying to figure out how to use phantomJS proxy server. 我试图弄清楚如何使用phantomJS代理服务器。 I would like to use a URL proxy ( http://multiwebproxy.com/:8080 ) to test my phantomJS ability to web scrape anonymously. 我想使用URL代理( http://multiwebproxy.com/:8080 )测试我的phantomJS匿名进行网络抓取的能力。 So far I tried to use the following code unsuccessfully. 到目前为止,我尝试不成功使用以下代码。

Any ideas for free \\ paid proxy service which is compatible with Selenium phantomJS? 与Selenium phantomJS兼容的免费\\付费代理服务的任何想法?

PROXY = 'http://multiwebproxy.com/:8080'

dcap = dict(DesiredCapabilities.PHANTOMJS)

dcap['proxy'] = {
"httpProxy":PROXY,
"ftpProxy":PROXY,
"sslProxy":PROXY,
"noProxy":None,
"proxyType":"MANUAL",
"class":"org.openqa.selenium.Proxy",
"autodetect":False
}

driver = webdriver.PhantomJS(executable_path=r'/home/ec2-user/utils/phantomjs-2.1.1-linux-x86_64/bin/phantomjs',desired_capabilities=dcap)

This is how you can use a proxy with PhantomJS in selenium 这是在硒中将PhantomJS与代理一起使用的方法

from selenium import webdriver
from selenium.webdriver.common.proxy import *

myProxy = "http://multiwebproxy.com/:8080"

proxy = Proxy({
  'proxyType': ProxyType.MANUAL,
  'httpProxy': myProxy,
  'ftpProxy': myProxy,
  'sslProxy': myProxy,
  'noProxy':''})

driver = webdriver.PhantomJS(proxy=proxy)

I don't know Python, but in C# there is a class called PhantomJSOptions , where you can call AddAdditionalCapability() with param CapabilityType.Proxy . 我不了解Python,但是在C#中有一个名为PhantomJSOptions的类,您可以在其中使用参数CapabilityType.Proxy调用AddAdditionalCapability()

Example: 例:

private PhantomJSDriver CreatePhantomJSDriver(string httpProxy)
{
    var options = new PhantomJSOptions();
    if (!string.IsNullOrEmpty(httpProxy))
    {
        options.AddAdditionalCapability(CapabilityType.Proxy, new Proxy { HttpProxy = httpProxy });
    }
    return new PhantomJSDriver(options);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM