- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一个网页的一部分,我需要在给定的时间间隔拍摄 gif 快照。快照需要全页大小分辨率,但正如我所说,它只会到达页面上的特定位置(在本例中它位于表格之后)。
像这样抓取页面快照图像的最佳方法是什么?我只想将它放入 cron 作业中,然后忘记它,但我还没有找到可以快速完成这项工作的工具。
按照@Eduardo 的出色指导,我实现了一个基于 phantomjs 和 imagemagick 的干净快速的解决方案(Mac:brew install phantomjs
& brew install imagemagick
):
*注意:如果您想完全删除 imagemagick,只需将以下内容添加到 rasterize.js:page.clipRect = { top: 10, left: 10, width: 500, height: 500 }
#! /usr/bin/env bash
# Used with PhantomJS - rasterize.js source: http://j.mp/xC7u1Z
refresh_seconds=30
while true; do
date_now=`date +"%Y-%m-%d %H%M"`
phantomjs rasterize.js $1 "${date_now}-original.png" # just sucking in the first arg from shell for the URL
convert "${date_now}-original.png" -crop 500x610+8+16 "${date_now}.png" # crop args: WIDTHxHEIGHT+LEFT_MARGIN+TOP_MARGIN
rm "${date_now}-original.png"
echo "Got image: ${date_now}.png - Now waiting ${refresh_seconds} seconds for next image..."
sleep ${refresh_seconds}
done
这里是上面phantomjs使用的js:
// As explained here: http://code.google.com/p/phantomjs/wiki/QuickStart
var page = new WebPage(),
address, output, size;
if (phantom.args.length < 2 || phantom.args.length > 3) {
console.log('Usage: rasterize.js URL filename');
phantom.exit();
} else {
address = phantom.args[0];
output = phantom.args[1];
page.viewportSize = { width: 600, height: 600 };
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
} else {
window.setTimeout(function () {
page.render(output);
phantom.exit();
}, 200);
}
});
}
最佳答案
这里已经回答了这个问题: How can I take a screenshot/image of a website using Python?
它在 09 年得到了回答,但该选项仍然非常有效。我将尝试使用更多选项进行扩展。
这些工具将为您获取整页快照,稍后您可以使用 imagemagick 轻松地对其进行剪辑。
最近您可能有的另一个选择是 Phantomjs . Phantom 是一个在节点上运行的 headless 浏览器,它允许您拍摄整个页面或页面的一部分。
看看this example :
var page = new WebPage(),
address, output, size;
if (phantom.args.length < 2 || phantom.args.length > 3) {
console.log('Usage: rasterize.js URL filename');
phantom.exit();
} else {
address = phantom.args[0];
output = phantom.args[1];
page.viewportSize = { width: 600, height: 600 };
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
} else {
window.setTimeout(function () {
page.render(output);
phantom.exit();
}, 200);
}
});
}
关于javascript - 如何从 shell 中截取网页的一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9390493/
下面是split截取获得 ? 1
我正在写一个小编辑。我想更改 QTextEdit 的默认行为,即在 Tab 时插入制表符被击中。相反,我想放 4 个空格。这样做的推荐方法是什么?我想关于子类化 keyPressedEvent ,但也
我正在寻找一种简单的方法来在我的 ASP 页面中截取 iFrame 的屏幕截图。我只是无法用 C# 实现它,而且我缺乏 Javascript 知识!有没有人知道实现这一目标的简单和最佳方法? 我正在尝
这让我感到困惑。 DirectX 绕过所有内容并直接与设备驱动程序对话,因此 GDI 和其他常用方法将不起作用 - 除非 Aero 被禁用(或不可用),否则出现的只是屏幕左上角的黑色矩形。我已经尝试了
我正在开发一个应用程序,当我按下按钮时,我想发送 2 个 View 的 2 个屏幕截图,并将其附加到电子邮件中。 这两个 View Controller 被称为 secondViewControlle
我尝试截取一个用 WPF 编写的应用程序,但应用程序没有被捕获,我是否必须使用特殊工具来截取屏幕截图? 最佳答案 您可以使用 RenderTargetBitmap从 WPF 控件生成图像。 p
以下是我的断言。 Assert.assertEquals(securityQuestionPage.UserName.getText().toString(),BaseClass.unsuccessf
我有一个 ImageView @property (strong, nonatomic) IBOutlet UIImageView *imageView; 我想截图。我的代码占据了整个屏幕。我已经查看
我必须编写一些 javascript 代码来截取网页的屏幕截图,但不能在前台渲染它。首先,这可能吗?我需要使用一些外部库吗?请给我一些想法:) 最佳答案 如果您正在谈论在 Firefox chrome
我想在我的 tableview 屏幕截图图像中包含导航栏。以下代码用于捕获整个 TableView ,我尝试了其他代码来捕获导航栏而不是整个 TableView 。可以同时进行吗? func scre
我使用以下代码截取我的 View : UIGraphicsBeginImageContextWithOptions(containerView.bounds.size, NO, [[UIScreen
我正在开发一个简单的相机应用程序。我有截取整个 Activity 的屏幕截图并将其写入 SD 卡的代码。问题是 Surfaceview 返回黑屏。 我想知道如何独立截取surfaceview的截图。这
基本上我想做的是: 我在页面上有一个 flash 游戏(例如 pacman) 我希望能够使用 javascript 打印该游戏的屏幕 这可能吗?我知道我可以将游戏 swf 包含在另一个 swf 中并使
我正在开发的应用程序使用 Collection View 单元格向用户显示数据。我希望用户能够共享单元格中包含的数据,但通常有太多单元格无法尝试调整大小并适合单个 iPhone 屏幕大小的窗口并获取屏
有人可以分享代码来截取网络浏览器控件的屏幕截图并将其保存在预定路径中。 我正在使用 VS 2008 .Net 3.5。 最佳答案 你可以使用 Control.DrawToBitmap() ,即使它在
在 String 中提供了两个截取字符串的方法,一个是从指定位置截取到字符串结尾,另一个是截取指定范围的内容。下面对这两种方法分别进行介绍。 1. substring(int beginIndex
如下所示: ? 1
MySQL字符串的拼接、截取、替换、查找位置。 常用的字符串函数: 函数 说明 CONCAT(s1,s2,...)
我想截取UIView(该 View 将包含签名)并将其保存到应用程序文件中的本地文件中,以便以后调用图像点显示在类似于 UIImageView 的内容中。下面是签名 UIView 背后的代码。 #im
下面的代码是截取当前页面的屏幕截图。 html2canvas中的url可以截图吗?我的意思是我有一个 URL 是 mydomain.com/home mydomain.com/home?id=2 my
我是一名优秀的程序员,十分优秀!