Selenium/PhantomJS raises error

前端 未结 4 2025
谎友^
谎友^ 2020-12-15 10:55

I\'m trying to run PhantomJS driver in Python but I\'m getting error. I\'ve read that I should pass the whole path as an argument but it di

相关标签:
4条回答
  • 2020-12-15 11:14

    Make the path in raw string, add 'r': 

    driver = webdriver.PhantomJS(executable_path=r'D:\Python\phantomjs-2.0.0-windows\bin\phantomjs.exe')
    
    0 讨论(0)
  • 2020-12-15 11:30

    For me none of the above solved the problem; I found the code:

    driver = webdriver.PhantomJS()
    

    Will only work for root...

    0 讨论(0)
  • 2020-12-15 11:34

    For simplicity's sake place the executable in the same directory as your script:

    driver = webdriver.PhantomJS() # now there's no need for a path
    
    0 讨论(0)
  • 2020-12-15 11:35

    For me, this works fine and also don't have to specify path for PhantomJS You need to install pip install phantomjs-binary binary package using pip

    pip install phantomjs-binary
    

    it will download a package of approx 60MB. and contains PhantomJS for windows, mac, and Linux as per the running environment. after that, you can use it

    from selenium import webdriver
    from phantomjs_bin import executable_path
    
    driver = webdriver.PhantomJS(executable_path=executable_path)
    
    0 讨论(0)
提交回复
热议问题