PhantomJS with Selenium: Message: 'phantomjs' executable needs to be in PATH

前端 未结 2 2040
别那么骄傲
别那么骄傲 2021-01-22 02:07

I having trouble installing PhantomJS to my project Following the suggestions from the similar question from so I defined the $PATH variable with executable path

相关标签:
2条回答
  • 2021-01-22 02:48

    This error message...

    No such file or directory: 'phantomjs': 'phantomjs'
    

    ...implies that the program was unable to locate the phantomjs binary.

    As you are on MAC OS X you need to download phantomjs-2.1.1-macosx.zip from Download PhantomJS page and extract (unzip) the content within your system. Next you can mention the absolute path of phantomjs binary passing the argument executable_path as follows:

    • MAC OS X example:

      from selenium import webdriver
      
      driver = webdriver.PhantomJS(executable_path='/path/to/phantomjs-2.1.1-xxx/bin/phantomjs')
      driver.get('https://www.google.com/')
      print(driver.title)
      driver.quit()
      
    • Windows OS example:

      from selenium import webdriver
      
      driver = webdriver.PhantomJS(executable_path=r'C:\\Utility\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe')
      driver.get('https://www.google.com/')
      print(driver.title)
      driver.quit()
      
    0 讨论(0)
  • 2021-01-22 02:52

    You need to give the path:

    browser = webdriver.PhantomJS(executable_path='Complete path/to/phantomjs')
    

    To find it use export PATH=${PATH:+$PATH:} in the command line as @Anderson commented.

    0 讨论(0)
提交回复
热议问题