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

后端 未结 7 1834
灰色年华
灰色年华 2020-12-05 13:59

I am attempting to run this script:

https://github.com/Chillee/coursera-dl-all

However, the script fails at the line session = webdriver.PhantomJS()

相关标签:
7条回答
  • 2020-12-05 14:46

    you need to download the DRIVER

    after that session = webdriver.PhantomJS("c:\driverPath")

    0 讨论(0)
  • 2020-12-05 14:48

    Why Don't you use the easiest way ever and past the phantomjs.exe

    into the Python scripts directory which is already added to the system environment the python directory path should be something like this

    C:\Users\[user]\AppData\Local\Programs\Python\Python[version]\Scripts
    # you can use it as following 
    from selenium import webdriver
    driver = webdriver.PhantomJS()
    
    0 讨论(0)
  • 2020-12-05 14:48

    This will work perfectly.

    import platform
    from os import getcwd
    from selenium import webdriver
    
    if (platform.system() == 'Windows'):
    driver = webdriver.PhantomJS(executable_path=getcwd() + "\phantomjs")
    
    if (platform.system() == 'Darwin'):
    driver = webdriver.PhantomJS(executable_path=getcwd() + "/phantomjs")
    
    0 讨论(0)
  • 2020-12-05 14:51

    You need to provide the executable path.This is for linux or more precisely Ubuntu.

    You should specify the executable file path(complete), not the directory path that contains the executable.

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

    It does not require any drivers.

    Worked well for me on Ubuntu 16.04.

    0 讨论(0)
  • 2020-12-05 14:52

    Working Solution:

    Assumming you are on windows - it is similar for linux

    1) download phantomjs here: http://phantomjs.org/download.html pick windows/linux accordingly

    2) unzip your phantomjs-2.1.1-windows.zip and save it to for example c drive such as C:\phantomjs-2.1.1-windows\bin (in here there is a phantomjs.exe that is the execute that your system needs)

    3) On Windows10 edit your environment path to include this bin folder C:\phantomjs-2.1.1-windows\bin such as this example

    4) you may or may not restart your machine. Done! it should work! (Webdriver looks for phantomjs.exe and it should be ready now)

    0 讨论(0)
  • 2020-12-05 14:53

    I solved same promlem with this command in command line

    export PATH=${PATH:+$PATH:}/home/<login>/phantomjs/bin
    

    It's work if /home/login/phantomjs/bin is the path for folder with executable 'phantomjs'.

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