在python中使用Selenium、PhantomJS和Tor
我正在尝试将phantomJS与selenium和Tor结合使用。我有以下资料:在python中使用Selenium、PhantomJS和Tor,python,selenium,phantomjs,tor,Python,Selenium,Phantomjs,Tor,我正在尝试将phantomJS与selenium和Tor结合使用。我有以下资料: from selenium import webdriver service_args = [ '--proxy=127.0.0.1:9050', ' --proxy-type=socks5', ] driver = webdriver.PhantomJS(service_args = service_args) 每次尝试连接时,我都会收到以下错误消息: WebDriver
from selenium import webdriver
service_args = [
'--proxy=127.0.0.1:9050',
' --proxy-type=socks5',
]
driver = webdriver.PhantomJS(service_args = service_args)
每次尝试连接时,我都会收到以下错误消息:
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
WebDriverException回溯(最近一次调用)
在()
4'--代理类型=socks5',
5 ]
---->6 driver=webdriver.PhantomJS(服务参数=service参数)
/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/webdriver.pyc in_uuuuuuuinit_uuuuuuu(self、可执行路径、端口、所需功能、服务参数、服务日志路径)
49 self.service=service(可执行路径,端口=port,
50服务参数=服务参数,日志路径=服务日志路径)
--->51自助服务启动()
52
53尝试:
/启动时的usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.pyc(self)
83计数=0
84尽管如此:
--->85 self.assert\u进程仍在运行()
86如果self.u可连接():
87休息
/断言中的usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.pyc仍在运行(self)
96提高WebDriverException(
97“服务%s意外退出。状态代码为:%s”
--->98%(self.path,返回\u代码)
99 )
100
WebDriverException:消息:服务phantomjs意外退出。状态代码是:255
PhantomJS和Selenium可以很好地使用Tor参数。任何帮助,使这项工作将不胜感激 尝试添加精确的phantomjs路径
driver = webdriver.PhantomJS(executable_path=<your_phantomjs_path>, service_args = service_args)
driver=webdriver.PhantomJS(可执行文件路径=,服务参数=服务参数)
这是一个旧的,但我来这里,因为我搜索的正是你想要做的
当我执行你的代码时,我得到了完全相同的行为
简单地删除第二个参数(“代理类型= SOCKS5”)中的空白,代码工作得很好。 因此,
从selenium导入webdriver 服务参数=[ “--proxy=127.0.0.1:9050”, “--代理类型=socks5”, ] driver=webdriver.PhantomJS(服务参数=service参数) from selenium import webdriver service_args = [ '--proxy=127.0.0.1:9050', '--proxy-type=socks5', ] driver = webdriver.PhantomJS(service_args = service_args)