python无法创建selenium.webdriver.PhantomJS

苹果的操作系统,python3.6

代码如下:

from selenium import webdriver
import time
driver = webdriver.PhantomJS(executable_path='/Users/apple/phantomjs/bin/phantomjs')
driver.get('http://pythonscraping.com/pages/javascript/ajaxDemo.html')
time.sleep(3)
print(driver.find_element_by_id('content').text)
driver.close()

错误信息:

WebDriverException            Traceback (most recent call last)
<ipython-input-3-ffd0972f34d5> in <module>()
----> 1 driver = webdriver.PhantomJS(executable_path='/Users/apple/phantomjs/bin/phantomjs')
      2 driver.get('http://pythonscraping.com/pages/javascript/ajaxDemo.html')
      3 time.sleep(3)
      4 print(driver.find_element_by_id('content').text)
      5 driver.close()

/Users/apple/anaconda/lib/python3.6/site-packages/selenium/webdriver/phantomjs/webdriver.py in __init__(self, executable_path, port, desired_capabilities, service_args, service_log_path)
     50             service_args=service_args,
     51             log_path=service_log_path)
---> 52         self.service.start()
     53 
     54         try:

/Users/apple/anaconda/lib/python3.6/site-packages/selenium/webdriver/common/service.py in start(self)
    100             time.sleep(1)
    101             if count == 30:
--> 102                 raise WebDriverException("Can not connect to the Service %s" % self.path)
    103 
    104     def assert_process_still_running(self):

WebDriverException: Message: Can not connect to the Service /Users/apple/phantomjs/bin/phantomjs
阅读 4.1k
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进