PhantomJS安装MacOSX&&Windows1、PhantomJS下载地址根据系统下载对应版本,macOS下载:phantomjs-2.1.1-macosx.zipWindows下载:phantomjs-2.1.1-windows.zip和解压到用户目录下,macOS解压路径:/User/xxx/phantomjs-2.1.1-macosxWindows解压路径:D:\phantomjs-2.1.1-windows,并重命名为D:\phantomjs2,PhantomJS不需要待安装,解压后即可使用WindowsPATH变量在“系统变量”选项区勾选PATH变量。如果不存在,则新建变量PATH,否则选择变量,点击“编辑”按钮,在“变量值”文本框开头添加D:\phantomjs\bin,开始-运行-输入cmd,输入phantomjs--version,如果能看到版本号,说明安装成功。macOSPATH变量如果用户目录下有.bash_profile,比如我的/User/xxx/.bash_profile,添加一行exportPATH="$PATH:/Users/xxx/phantomjs-2.1.1-macosx/bin"否则创建一个新的。bash_profile,然后添加上面的内容,在终端输入phantomjs--version。如果能看到版本号,说明安装成功。3、使用npm安装时,如果环境变量中没有pha??ntomjs,它会从github上下载安装phantomjs,但是你知道吗?大多数情况下会超时,即使你把npm的镜像换成淘宝,结果还是一样。PhantomJSnotfoundonPATHD下载https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-macosx.zip保存到/var/folders/hn/55rkvgy97797tgx6cld83zl80000gn/T/phantomjs/phantomjs-2.1.1-macosx.zip那么聪明的你以为可以使用npminstall-gphantomjs,但是现实告诉你npmWARNdeprecatedphantomjs@2.1.7:Packagerenamedtophantomjs-prebuilt。请将“phantomjs”包引用更新为“phantomjs-prebuilt”npmWARNdeprecatedtough-cookie@2.2.2:ReDoS漏洞解析Set-Cookiehttps://nodesecurity.io/advisories/130npmWARNdeprecatednode-uuid@1.4.8:使用uuid模块代替/usr/local/bin/phantomjs->/usr/local/lib/node_modules/phantomjs/bin/phantomjs>phantomjs@2.1.7install/usr/local/lib/node_modules/phantomjs>nodeinstall.jsConsideringPhantomJSfoundat/usr/local/bin/phantomjsLookslookslikean`npminstall-g`错误检查路径,continuing{错误:在Function.Module._resolveFilename(module.js:469:15)在Function.Module._load(module.js:417)找不到模块'/usr/local/lib/node_modules/phantomjs/lib/location':25)在Module.require(module.js:497:17)在require(internal/module.js:20:19)在getLocationInLibModuleIfMatching(/usr/local/lib/node_modules/phantomjs/install.js:332:19)在Promise._successFn(/usr/local/lib/node_modules/phantomjs/install.js:389:28)在nextTickCallback(/usr/local/lib/node_modules/phantomjs/node_modules/kew/kew.js:47:28)at_combinedTickCallback(internal/process/next_tick.js:67:7)atprocess._tickCallback(internal/process/next_tick.js:98:9)code:'MODULE_NOT_FOUND'}下载https://github.com/Medium/phantomjs/releases/download/v2.1.1//phantomjs-2.1.1-macosx.zip保存到/usr/local/lib/node_modules/phantomjs/phantomjs/phantomjs-2.1.1-macosx.zipReceiving...回到原点,这是一个npm问题吗?我会用cnpm试试看,你足够聪明,认为你可以使用cnpminstall-gphantomjs,现在是这样Downloadingphantomjsto/usr/local/lib/node_modules/phantomjs_tmpCopying/usr/local/lib/node_modules/phantomjs_tmp/.2.1.7@phantomjsto/usr/local/lib/node_modules/phantomjsInstallingphantomjs'sdependenciesto/usr/local/lib/node_modules/phantomjs/node_modules[1/8]progress@~1.1.8安装在node_modules/.1.1.8@progress...[8/8]request@~2.67.0安装在node_modules/.2.67.0@requestexecutepostinstall1scripts...[1/1]scripts.installphantomjs@2.1.7+deprecatedrun"nodeinstall.js"PhantomJSnotfoundonPATHPhantominstallationfailedTypeError:Pathmustbeastring.在Object.join(path.js:1211:7)的assertPath(path.js:7:11)收到未定义安装失败!错误:安装后错误,请在重试前删除node_modules!运行“sh-cnodeinstall.js”错误,退出代码1错误:安装后错误,请在重试前删除node_modules!运行“sh-cnodeinstall.js”错误,在ChildProcess.proc.on.code(/usr/local/lib/node_modules/cnpm/atProcess.ChildProcess._handle.onexit(internal/child_process.js:226:5)npminstall版本:2.26.2npminstallargs:/usr/local/bin/node/usr/local/lib/node_modules/cnpm/node_modules/npminstall/bin/install.js--china--userconfig=/Users/azmake/.cnpmrc--disturl=https://npm.taobao.org/mirrors/node--registry=https://registry.npm.taobao.org-gphantomjs看到提示Installfail!错误:安装后错误,请在重试前删除node_modules!我勒个去?不跟你玩了sudonpmuninstall-gphantomjssudocnpmuninstall-gphantomjssudorm-rf/usr/local/lib/node_modules/phantomjs然后你觉得可以用HomeBrew安装brewinstallphantomjsok,安装完成,打开终端,输入phantomjs--version,可以看到版本号,一起正常,可以愉快的玩,然后愉快的开始npminstall,然后发现项目中使用phantomjs无法验证phantomjs,然后下载https://github。com/Medium/phantomjs/releases/download/v2.1.1//phantomjs-2.1.1-macosx.zip保存到/usr/local/lib/node_modules/phantomjs/phantomjs/phantomjs-2.1.1-macosx.zipReceiving...总结1.可以使用cnpminstall安装使用phantomjs的项目的node_modules。cnpm会使用phantomjs-prebuilt代替phantomjs,不会中途翻车。2.下载安装phantomjs,并配置好环境变量,这样无论是cnpminstall还是npminstall都可以使用phantomjs,并且不会报pycharm中找不到phantomjs的错误
