开源Nodejs项目推荐:抓取网站截图

抓取网站截图

很多网页特别长,直接的电脑截图非常麻烦,用ps等工具也非常麻烦,所以很多人都问我有木有自动抓出截图的软件

Node.js里是有的

推荐pageres

首先全局安装

$ PHANTOMJS_CDNURL=https://npm.taobao.org/dist/phantomjs npm install phantomjs --registry=https://registry.npm.taobao.org --no-proxy
$ npm install --global pageres-cli

 

执行

screenshot.png

效果如下

screenshot-output.png

说明:此模块依赖PhantomJS,请备好梯子或者用文中的国内镜像

嵌入代码中

通过shell是可以做,这是给其他语言调用的,对于Node.js,你可以使用对应模块就好了

https://github.com/sindresorhus/pageres

$ npm install --save pageres

 

PhantomJS, which is used for generating the screenshots, is installed automagically, but in some rare cases it might fail to and you'll get an Error: spawn EACCES error. Download PhantomJS manually and reinstall pageres if that happens.

用法

const Pageres = require('pageres');

const pageres = new Pageres({delay: 2})
    .src('yeoman.io', ['480x320', '1024x768', 'iphone 5s'], {crop: true})
    .src('todomvc.com', ['1280x1024', '1920x1080'])
    .dest(__dirname)
    .run()
    .then(() => console.log('done'));

 

转自:https://my.oschina.net/nodeonly/blog/662120

posted @   mingruqi  阅读(374)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示