如何使用ruby和unix服务器截取网页截图? [英] How do I take screenshots of web pages using ruby and a unix server?

查看:150
本文介绍了如何使用ruby和unix服务器截取网页截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试以编程方式创建大量网页的缩略图图像,这些图像位于我自己的基于ruby / rails的网站上。

I'm trying to programatically create thumbnail images of a large number of web pages that are hosted on my own ruby/rails-based website.

我想能够编写一段独立的ruby,看起来像这样:

I want to be able to code a stand-alone bit of ruby that looks something like this:

require 'awesome-screenshot-maker'

items.each do |id|
  url = "http://foo.com/bar/#{id}"
  shooter = AwesomeScreenshotMaker.new(0.2) # thumbnails are 20% of original
  shooter.capture(url, "/images/thumbnail-#{id}.png")
end

I需要在Linux,Solaris和Mac OS X上构建awesome-screenshot-maker库(及其依赖项)非常容易。理想情况下,它将使用一个gem install命令进行安装。

I need the awesome-screenshot-maker library (and its dependencies) to be fairly easy to build on Linux, Solaris and Mac OS X. Ideally it will install with a single 'gem install' command.

我花了下午的时间探索各种选项,包括 Moz snap shooter webkit2png rbwebkitgtk 。他们都在正确的领域,但似乎没有在所有三个平台上工作。

I've spent the afternoon exploring various options, including Moz snap shooter, webkit2png and rbwebkitgtk. They are all in the right area, but none seem to work on all three platforms.

如果我愿意从我的导轨输出PDF,RMagick看起来像一个可能的选项应用程序(而不是网页),但这使我感到哈克。在Mac OS X上运行RMagic和imagemagick也很麻烦。

RMagick looks like a possible option if I'm willing to output PDFs from my rails app (instead of web pages), but that strikes me as hacky. It's also very laborious to get RMagic and imagemagick up and running on Mac OS X.

是否有这样的库可以在三个平台上轻松设置?

Does such a library exist that can easily be setup on three platforms?

推荐答案

Selenium RC 有一个Ruby界面,并可以使用 capture_screenshot(文件名,kwargs)

Selenium RC has a Ruby interface and can grab a screenshot using capture_screenshot(filename,kwargs).

然后您必须将其缩小为缩略图。

You'd then have to shrink it to a thumbnail.

这篇关于如何使用ruby和unix服务器截取网页截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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