[英]Using Selenium, PhantomJS and Tor in python
I'm trying to use phantomJS with selenium and Tor. 我正在尝试使用含有硒和Tor的phantomJS。 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)
Every time I try to connect, I get the following error message: 每次我尝试连接时,都会收到以下错误消息:
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 the Tor parameters. PhantomJS和Selenium可以与Tor参数一起使用。 Any help to get this working would be appreciated!
任何帮助,让这项工作将不胜感激!
This is an old one, but I came here, because I searched for exactly what you wanted to do. 这是一个旧的,但我来到这里,因为我搜索了你想要做的事情。
When I executed your code, I got exactly the same behaviour. 当我执行你的代码时,我得到了完全相同的行为。
Simply remove the blank space at second argument ('--proxy-type=socks5') and your code is working nicely. 只需删除第二个参数的空格('--proxy-type = socks5'),您的代码就可以正常运行。
Thus, 从而,
from selenium import webdriver service_args = [ '--proxy=127.0.0.1:9050', '--proxy-type=socks5', ] driver = webdriver.PhantomJS(service_args = service_args)
尝试添加您的确切phantomjs路径?
driver = webdriver.PhantomJS(executable_path=<your_phantomjs_path>, service_args = service_args)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.