我试图让 Selenium 在 Windows 机器上使用 phantomjs。我的代码编译没有任何错误:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import cookielib
import re
from splinter import Browser
driver = webdriver.PhantomJS('C:/Program Files (x86)/phantomjs-1.9.2-windows')
Run Code Online (Sandbox Code Playgroud)
但是每次我运行它我都会收到错误
Traceback (most recent call last):
File "E:/~PROJECT/disinfo/py/bs.py", line 8, in <module>
driver = webdriver.PhantomJS('C:/Program Files (x86)/phantomjs-1.9.2-windows')
File "C:\Python27\lib\site-packages\selenium\webdriver\phantomjs\webdriver.py", line 50, in __init__
self.service.start()
File "C:\Python27\lib\site-packages\selenium\webdriver\phantomjs\service.py", line 63, in start
raise WebDriverException("Unable to start phantomjs with ghostdriver.", e)
selenium.common.exceptions.WebDriverException: Message: 'Unable to start phantomjs with ghostdriver.' ; Screenshot: available via screen
Run Code Online (Sandbox Code Playgroud)
我已经收到这个错误几个小时了。“无法使用 ghostdriver 启动 phantomjs”。网上最简单的例子展示了先用 PIP 安装 selenium,然后用 NodeJS NPM 安装 phantomjs,我就是这样做的。Selenium 的位置也在我的 PYTHONPATH 中。坦率地说,我不知道这东西到底要我做什么。有任何想法吗?
小智 19
我遇到了同样的问题。我需要提供 exe 的完整路径,如文档中所述:
from selenium import webdriver
driver = webdriver.PhantomJS(executable_path='C:\phantomjs-1.9.2\phantomjs.exe')
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
24026 次 |
最近记录: |