Using Selenium, PhantomJS and Tor in python

I am trying to use phantomJS with selenium and Tor. I have the following:

from selenium import webdriver
service_args = [
        '--proxy=127.0.0.1:9050',
        ' --proxy-type=socks5',
    ]
driver = webdriver.PhantomJS(service_args = service_args)

Each time I try to connect, the following error message appears:

WebDriverException                        Traceback (most recent call last)
<ipython-input-2-98e27eb2ae26> in <module>()
  4             ' --proxy-type=socks5',
  5     ]
----> 6 driver = webdriver.PhantomJS(service_args = service_args)

/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs    /webdriver.pyc in __init__(self, executable_path, port, desired_capabilities,    service_args, service_log_path)
 49         self.service = Service(executable_path, port=port,
 50             service_args=service_args, log_path=service_log_path)
---> 51         self.service.start()
 52 
 53         try:

/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.pyc in start(self)
 83         count = 0
 84         while True:
---> 85             self.assert_process_still_running()
 86             if self.is_connectable():
 87                 break

/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.pyc in assert_process_still_running(self)
 96             raise WebDriverException(
 97                 'Service %s unexpectedly exited. Status code was: %s'
---> 98                 % (self.path, return_code)
 99             )
100 

WebDriverException: Message: Service phantomjs unexpectedly exited. Status code was: 255

PhantomJS and Selenium work fine with Tor options. Any help to get this job would be appreciated!

+4
source share
2 answers

It is old, but I came here because I was looking for exactly what you wanted to do.

When I executed your code, I got exactly the same behavior.

Just remove the empty space in the second argument ('--proxy-type = socks5') and your code works well.

In this way,

    from selenium import webdriver
    service_args = [
        '--proxy=127.0.0.1:9050',
        '--proxy-type=socks5',
    ]
    driver = webdriver.PhantomJS(service_args = service_args)
+3

phantomjs?

driver = webdriver.PhantomJS(executable_path=<your_phantomjs_path>, service_args = service_args)
0

All Articles