2016-06-28 43 views
0

我跟着this link,现在当我输入phan,然后选项卡(\t)它会自动完成phantomJS。使用python在linux上运行phantomjs

然而,如果我跑phantomJS -vphantomJS --version我得到:

bash: /usr/local/bin/phantomjs: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory 

此外,如果我尝试运行:

>>> from selenium import webdriver 
>>> driver = webdriver.PhantomJS() 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 50, in __init__ 
    service_args=service_args, log_path=service_log_path) 
    File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/phantomjs/service.py", line 50, in __init__ 
    service.Service.__init__(self, executable_path, port=port, log_file=open(log_path, 'w')) 
IOError: [Errno 13] Permission denied: 'ghostdriver.log' 
>>> 

如果我尝试按照this I get

>>> import os 
>>> driver = webdriver.PhantomJS(service_log_path=os.path.devnull) 
Exception AttributeError: "'Service' object has no attribute 'log_file'" in <bound method Service.__del__ of <selenium.webdriver.phantomjs.service.Service object at 0x7f182ec13690>> ignored 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 51, in __init__ 
    self.service.start() 
    File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 69, in start 
    os.path.basename(self.path), self.start_error_message) 
selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH. 

>>> 

是我的硒/ phatnomjs安装有适当的权利?

我创建了一个目录/home/ec2-user/temp并设置:

chmod 777 /home/ec2-user/temp 

然而

>>> from selenium import webdriver 
>>> driver = webdriver.PhantomJS(service_log_path='/home/ec2-user/temp/ghostdriver.log') 

产量:

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 51, in __init__ 
    self.service.start() 
    File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 69, in start 
    os.path.basename(self.path), self.start_error_message) 
selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH. 

如果我型我which phantomjs得到:

$ which phantomjs 
/usr/local/bin/phantomjs 
+0

你确定大写字母吗?它通常是'phantomjs'而不是'phantomJS'。输入'which phantomjs'来查看它的安装位置。 –

+0

@ArtjomB。我更新了这个问题。 –

+0

您是否通过npm安装了PhantomJS?检查它是否是一个符号链接或实际可执行文件的sh封装器 –

回答