- A+
所属分类:未分类
安装nodejs和npm
下载地址:
https://nodejs.org/zh-cn/
下载下来直接默认安装就行,安装成功后,看看是否安装成功,如下:
更新npm:
问题1:
C:\Users\Administrator>npm i npm npm WARN saveError ENOENT: no such file or directory, open 'C:\Users\Administrator\package.json' npm notice created a lockfile as package-lock.json. You should commit this file. npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Administrator\package.json' npm WARN Administrator No description npm WARN Administrator No repository field. npm WARN Administrator No README data npm WARN Administrator No license field. + npm@6.4.1 added 387 packages from 770 contributors and audited 5019 packages in 199.568s found 0 vulnerabilities
解决办法:
npm install -g cnpm --registry=https://registry.npm.taobao.org
安装puppeteer
输入如下命令安装
npm i puppeteer
如下,则说明开始下载安装:
C:\Users\Administrator>npm i puppeteer
> puppeteer@1.10.0 install C:\Users\Administrator\node_modules\puppeteer
> node install.js
Downloading Chromium r599821 - 135.9 Mb [ ] 0% 54.2s
注:
有时国外网络问题,一直卡,所有最好通过cnpm安装能快些,如下:
cnpm i puppeteer
安装完成,如下图:
cd D:\Program Files\nodejs\node_modules D:\Program Files\nodejs\node_modules>cnpm i puppeteer √ Installed 1 packages Downloading Chromium r599821 - 135.9 Mb [====================] 99% 0.0s Chromium downloaded to C:\Users\Administrator\node_modules\_puppeteer@1.10.0@puppeteer\.local-chromium\win64-599821 √ Run 1 scripts Recently updated (since 2018-11-20): 1 packages (detail see file C:\Users\Administrator\node_modules\.recently_updates.txt) Today: → puppeteer@1.10.0 › mime@^2.0.3(2.4.0) (06:34:54) √ All packages installed (42 packages installed from npm registry, used 26s(network 2s), speed 256.1kB/s, json 40(97.37kB), tarball 483.73kB)
装完后测试一下,如下:
创建一个js文件,我这里叫hello.js,内容如下:
const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch({headless: false}); const page = await browser.newPage(); await page.goto('https://www.baidu.com', {waitUntil: 'baidu'}); await page.pdf({path: 'baidu.pdf', format: 'A4'}); await browser.close(); })();
执行该文件,命令如下:
node hello.js
出现浏览器弹出来,并生成pdf文件就可以了
- 安卓客户端下载
- 微信扫一扫
- 微信公众号
- 微信公众号扫一扫