美文网首页
linux phantomjs 笔记

linux phantomjs 笔记

作者: jojo1313 | 来源:发表于2017-10-19 11:45 被阅读0次

    问题selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH.

    centos环境:

    解决方法:

    官网下载phantomjs安装包后解压到python对应的site-packages;

    插入如下代码即可:

    phantomJSdriver = '/xxxxx/site-packages/bin/phantomjs'
    
    os.environ["webdriver.phantomjs.driver"] = phantomJSdriver
    
    browser = webdriver.PhantomJS(phantomJSdriver)
    

    windows环境:
    参考:http://www.codes51.com/itwd/4406153.html
    解决方法:

    下载安装包解压到python对应的site-packages;

    from selenium import webdriver
    
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
    
    dcap =dict(DesiredCapabilities.PHANTOMJS)
    
    dcap["phantomjs.page.settings.userAgent"] = ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:25.0) Gecko/20100101 "
    
    "Firefox/25.0 ")
    
    if__name__=='__main__':
    
           obj = webdriver.PhantomJS(executable_path='C:\Users\jojo\AppData\Local\Continuum\Anaconda2\Lib'
    
    '\site-packages\phantomjs.exe',desired_capabilities=dcap)
    
           obj.get('http://www.chinaxiaokang.com/caijingpindao/gongsichanye/20171017/267628.html')
    
           print dir(obj)
    
           print obj.title
    
           obj.quit()
    

    相关文章

      网友评论

          本文标题:linux phantomjs 笔记

          本文链接:https://www.haomeiwen.com/subject/ufduuxtx.html