Python Selenium PhantomJS代理问题

时间:2014-07-07 05:19:16

标签: python selenium proxy phantomjs

我可以在PhantomJS上完全正常运行以下命令:

phantomjs --ignore-ssl-errors=true --cookies-file=test.cookies --disk-cache=true --local-to-remote-url-access=true --proxy=user:password@xxxx.xxx.xxxx.xxx:xxxx --proxy-auth=user:password --web-security=false --debug=yes test.js

我的test.js是:

console.log('Loading a web page');
var page = require('webpage').create();
var url = 'http://xxx.xxxx.xxx'; //internal service
page.open(url, function (status) {

  if (status !== 'success') {
    console.log('Unable to access network');
  } else {
    var p = page.evaluate(function () {
    return document.getElementsByTagName('html')[0].innerHTML
    });
    console.log(p);
  }
  page.render('webaccess.png');
  phantom.exit();
});

这完全没问题。但是,当我尝试使用service-args在python中使用selenium做同样的事情时,它给了我一个代理错误:

from selenium import webdriver
PJS_PATH = './phantom/bin/phantomjs'
service_args = [
    '--ignore-ssl-errors=true',
    '--cookies-file=test.cookies',
    '--disk-cache=true',
    '--local-to-remote-url-access=true',
    '--proxy=xxxx.xxx.xxxx.xxx:xxxx',
    '--proxy-type=http',
    '--proxy-auth=user:pass',
    '--web-security=false',
    ]

driver = webdriver.PhantomJS(pjs_path,service_args=service_args)

---> 14 driver = webdriver.PhantomJS(pjs_path,service_args=service_args)
 .local/lib/python2.7/site-packages/selenium-2.42.1-py2.7.egg/selenium/webdriver     /phantomjs/webdriver.pyc in __init__(self, executable_path, port, desired_capabilities, service_args, service_log_path)
     53             RemoteWebDriver.__init__(self,
     54                 command_executor=self.service.service_url,
---> 55                 desired_capabilities=desired_capabilities)
     56         except:
     57             self.quit()

.local/lib/python2.7/site-packages/selenium-2.42.1-py2.7.egg/selenium/webdriver/remote/webdriver.pyc in __init__(self, command_executor, desired_capabilities, browser_profile, proxy, keep_alive)
     71         self.error_handler = ErrorHandler()
     72         self.start_client()
---> 73         self.start_session(desired_capabilities, browser_profile)
     74         self._switch_to = SwitchTo(self)
     75         self._mobile = Mobile(self)

.local/lib/python2.7/site-packages/selenium-2.42.1-py2.7.egg/selenium/webdriver/remote/webdriver.pyc in start_session(self, desired_capabilities, browser_profile)
    119             desired_capabilities['firefox_profile'] = browser_profile.encoded
    120         response = self.execute(Command.NEW_SESSION, {
--> 121             'desiredCapabilities': desired_capabilities,
    122         })
    123         self.session_id = response['sessionId']

.local/lib/python2.7/site-packages/selenium-2.42.1-py2.7.egg/selenium/webdriver/remote/webdriver.pyc in execute(self, driver_command, params)
    171         response = self.command_executor.execute(driver_command, params)
    172         if response:
--> 173             self.error_handler.check_response(response)
    174             response['value'] = self._unwrap_value(
    175                 response.get('value', None))

.local/lib/python2.7/site-packages/selenium-2.42.1-py2.7.egg/selenium/webdriver/remote/errorhandler.pyc in check_response(self, response)
    134             if exception_class == ErrorInResponseException:
    135                 raise exception_class(response, value)
--> 136             raise exception_class(value)
    137         message = ''
    138         if 'message' in value:

WebDriverException: Message: 'ACCESS DENIED MESSAGE' 

我服用selenium。版本 2.42.1

selenium.__version__

'2.42.1'

0 个答案:

没有答案