如何使用PhantomJS渲染页面的一部分? [英] How to render part of a page with PhantomJS?

查看:527
本文介绍了如何使用PhantomJS渲染页面的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Phantom.JS将各个HTML元素渲染到PNG中。有谁知道这是否可能?另外,我如何使用Phantom.js呈现用户已经在查看的页面?

I would like to render individual HTML elements into PNGs using Phantom.JS. Does anyone know if this is possible? Also, how would I use Phantom.js to render a page that the user is already looking at?

推荐答案

仅渲染部分您需要为页面设置clipRect属性然后呈现它的页面。

To only render part of a page you need to set the clipRect attribute for the page and then render it.

var clipRect = document.querySelector(selector).getBoundingClientRect();
page.clipRect = {
    top:    clipRect.top,
    left:   clipRect.left,
    width:  clipRect.width,
    height: clipRect.height
};
page.render('capture.png');

我不明白你问题的第二部分。 Phantom.js无头,意味着没有用户正在看的实际显示。

I don't understand the second part of your question. Phantom.js is headless meaning that there is no actual display that a user is looking at.

这篇关于如何使用PhantomJS渲染页面的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆