简体   繁体   English

使用 npm 错误安装 phantomjs

[英]Installing phantomjs using npm error

I'm doing a unit testing for my javascript codes.我正在对我的 javascript 代码进行单元测试。 I prefer to use a headless browser for easier running.我更喜欢使用无头浏览器来更轻松地运行。 It goes well when I installed some dependencies but when I install phantomjs, it has an error.当我安装了一些依赖项时它很顺利,但是当我安装 phantomjs 时,它有一个错误。

C:\\Phantomjs>npm install -g phantomjs npm WARN deprecated phantomjs@2.1.7: Package renamed to phantomjs-prebuilt. C:\\Phantomjs>npm install -g phantomjs npm WARN deprecated phantomjs@2.1.7: 包重命名为 phantomjs-prebuilt。 Plea se update 'phantomjs' package references to 'phantomjs-prebuilt' npm WARN deprecated node-uuid@1.4.8: Use uuid module instead npm WARN deprecated tough-cookie@2.2.2: ReDoS vulnerability parsing Set-Cookie h ttps://nodesecurity.io/advisories/130 C:\\Users.ra\\AppData\\Roaming\\npm\\phantomjs -> C:\\Users.ra\\AppDa ta\\Roaming\\npm\\node_modules\\phantomjs\\bin\\phantomjs请更新 'phantomjs' 包引用到 'phantomjs-prebuilt' npm WARN deprecated node-uuid@1.4.8:使用 uuid 模块代替 npm WARN deprecated twin-cookie@2.2.2:ReDoS 漏洞解析 Set-Cookie h ttps:/ /nodesecurity.io/advisories/130 C:\\Users.ra\\AppData\\Roaming\\npm\\phantomjs -> C:\\Users.ra\\AppData\\Roaming\\npm\\node_modules\\phantomjs\\bin\\phantomjs

phantomjs@2.1.7 install C:\\Users.ra\\AppData\\Roaming\\npm\\node_modules\\ phantomjs node install.js phantomjs@2.1.7 安装 C:\\Users.ra\\AppData\\Roaming\\npm\\node_modules\\ phantomjs node install.js

Considering PhantomJS found at C:\\Users.ra\\AppData\\Roaming\\npm\\phantomj s.CMD Looks like an npm install -g on windows;考虑到 PhantomJS 发现在 C:\\Users.ra\\AppData\\Roaming\\npm\\phantomj s.CMD 看起来像 windows 上的npm install -g skipping installed version.跳过已安装的版本。 Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1//phanto mjs-2.1.1-windows.zip Saving to C:\\Users.ra\\AppData\\Local\\Temp\\phantomjs\\phantomjs-2.1.1-wind ows.zip Using proxy http://.ra :******@proxy:3128/ Receiving...下载https://github.com/Medium/phantomjs/releases/download/v2.1.1//phanto mjs-2.1.1-windows.zip 保存到 C:\\Users.ra\\AppData\\Local\\Temp\\phantomjs\\phantomjs -2.1.1-wind ows.zip 使用代理http://.ra :******@proxy:3128/ 正在接收...

Error making request.提出请求时出错。 Error: tunneling socket could not be established, statusCode=502 at ClientRequest.onConnect (C:\\Users.ra\\AppData\\Roaming\\npm\\node_mo dules\\phantomjs\\node_modules\\tunnel-agent\\index.js:165:19) at Object.onceWrapper (events.js:320:30) at emitThree (events.js:135:13) at ClientRequest.emit (events.js:216:7) at Socket.socketOnData (_http_client.js:470:11) at emitOne (events.js:115:13) at Socket.emit (events.js:210:7) at addChunk (_stream_readable.js:264:12) at readableAddChunk (_stream_readable.js:251:11) at Socket.Readable.push (_stream_readable.js:209:10)错误:无法建立隧道套接字,ClientRequest.onConnect (C:\\Users.ra\\AppData\\Roaming\\npm\\node_mo dules\\phantomjs\\node_modules\\tunnel-agent\\index.js:165:19) 处的 statusCode=502 Object.onceWrapper (events.js:320:30) at emitThree (events.js:135:13) at ClientRequest.emit (events.js:216:7) at Socket.socketOnData (_http_client.js:470:11) at在 Socket.emit (events.js:210:7) 在 addChunk (_stream_readable.js:264:12) 在 readableAddChunk (_stream_readable.js:251:11) 在 Socket.Readable 上的 emitOne (events.js:115:13)。推送(_stream_readable.js:209:10)

Please report this full log at https://github.com/Medium/phantomjs npm WARN Error: EPERM: operation not permitted, scandir 'C:\\Users.ra\\Ap pData\\Roaming\\npm\\node_modules\\phantomjs\\node_modules\\dashdash\\node_modules' npm WARN { Error: EPERM: operation not permitted, scandir 'C:\\Users.ra \\AppData\\Roaming\\npm\\node_modules\\phantomjs\\node_modules\\dashdash\\node_modules' npm WARN stack: 'Error: EPERM: operation not permitted, scandir \\'C:\\Users\\p ardillo.ra\\AppData\\Roaming\\npm\\node_modules\\phantomjs\\node_modules\\dashda sh\\node_modules\\'', npm WARN errno: -4048, npm WARN code: 'EPERM', npm WARN syscall: 'scandir', npm WARN path: 'C:\\Users\\.ra\\AppData\\Roaming\\npm\\node_modules\\p hantomjs\\node_modules\\dashdash\\node_modules' } npm ERR!请在https://github.com/Medium/phantomjs npm WARN 报告此完整日志错误:EPERM: operation not allowed, scandir 'C:\\Users.ra\\Ap pData\\Roaming\\npm\\node_modules\\phantomjs\\node_modules\\dashdash \\node_modules' npm WARN { Error: EPERM: operation not allowed, scandir 'C:\\Users.ra \\AppData\\Roaming\\npm\\node_modules\\phantomjs\\node_modules\\dashdash\\node_modules' npm WARN stack: 'Error: EPERM: operation not允许,scandir \\'C:\\Users\\p ardillo.ra\\AppData\\Roaming\\npm\\node_modules\\phantomjs\\node_modules\\dashda sh\\node_modules\\'', npm WARN errno: -4048, npm WARN code: 'EPERM', npm WARN 系统调用:'scandir',npm WARN 路径:'C:\\Users\\.ra\\AppData\\Roaming\\npm\\node_modules\\p hantomjs\\node_modules\\dashdash\\node_modules' } npm ERR! code ELIFECYCLE npm ERR!代码 ELIFECYCLE npm ERR! errno 1 npm ERR!错误号 1 npm 错误号! phantomjs@2.1.7 install: node install.js npm ERR! phantomjs@2.1.7 安装: node install.js npm ERR! Exit status 1 npm ERR!退出状态 1 npm ERR! npm ERR! npm 错误! Failed at the phantomjs@2.1.7 install script. phantomjs@2.1.7 安装脚本失败。 npm ERR! npm 错误! This is probably not a problem with npm.这可能不是 npm 的问题。 There is likely additional log ging output above.`上面可能有额外的日志输出。`

What should I do?我该怎么办?

The simplest installation method is最简单的安装方法是

  1. Install NodeJS安装Node.js
  2. Using Node's package manager install phantomjs: npm -g install phantomjs-prebuilt使用 Node 的包管理器安装 phantomjs: npm -g install phantomjs-prebuilt

After installation, you may use phantom as simple as:安装后,您可以像使用 phantom 一样简单:

driver = webdriver.PhantomJS() # or add to your PATH
driver.set_window_size(1024, 768) # optional
driver.get('https://google.com/')
driver.save_screenshot('screen.png') # save a screenshot to disk
sbtn = driver.find_element_by_css_selector('button.gbqfba')
sbtn.click()

If your system path environment variable isn't set correctly, you'll need to specify the exact path as an argument to webdriver.PhantomJS() .如果您的系统路径环境变量设置不正确,您需要将确切路径指定为webdriver.PhantomJS()的参数。 Replace this:替换这个:

driver = webdriver.PhantomJS() # or add to your PATH

... with the following: ...具有以下内容:

driver = webdriver.PhantomJS(executable_path='/usr/local/lib/node_modules/phantomjs/lib/phantom/bin/phantomjs')

References:参考资料:

Try run npm install phantomjs-prebuilt尝试运行npm install phantomjs-prebuilt

phantomjs name changed to phantomjs-prebuilt on Pre-2.0 version release. phantomjs名称在 Pre-2.0 版本发布时更改为phantomjs-prebuilt

Source: view this link for detailed description of the name change.来源:查看此链接以了解名称更改的详细说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM