如何使用 ruby 和 unix 服務器截取網頁截圖? (How do I take screenshots of web pages using ruby and a unix server?)


問題描述

如何使用 ruby 和 unix 服務器截取網頁截圖? (How do I take screenshots of web pages using ruby and a unix server?)

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.

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 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.

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.

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?

‑‑‑‑‑

參考解法

方法 1:

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.

方法 2:

you might want to try this:

http://www.pageglimpse.com/

方法 3:

There is https://github.com/maxwell/screencap which uses phantom.js

方法 4:

There is a ruby wrapper for PageGlimpse available:

http://code.squidchunks.com/pageglimpse/

Unfortunately, the Terms of Use state that "You must not use or launch any automated system, including without limitation, "offline readers", "spiders," etc. to capture data provided by the Service."

方法 5:

You can use the gem gastly.

Gastly.capture('http://google.com', 'output.png')

(by LeeGene GotimerNoCarrierkatzmopolitanuser88254mgrachev)

參考文件

  1. How do I take screenshots of web pages using ruby and a unix server? (CC BY‑SA 3.0/4.0)

#screenshot #unix #gtk #rmagick #ruby






相關問題

沒有 iPhone,如何使用 XCode 截屏? (Without iPhone, how to take screenshot with XCode?)

mapViewDidFinishLoadingMap:調用過早 (mapViewDidFinishLoadingMap: called too early)

屏幕截圖上的窗口沒有消失 (Window not disappearing on Screenshot)

Appium 中用於混合應用程序的多個屏幕截圖 (Multiple Screenshots in Appium for Hybrid Apps)

在Linux上通過Python腳本拍攝屏幕截圖 (Take a screenshot via a Python script on Linux)

如何使用服務器端腳本生成網頁的屏幕截圖? (How can I generate a screenshot of a webpage using a server-side script?)

如何使用 ruby 和 unix 服務器截取網頁截圖? (How do I take screenshots of web pages using ruby and a unix server?)

使用 jquery 生成網站的屏幕截圖 (generating a screenshot of a website using jquery)

畫面區域的選擇 (Selection of screen area)

使用 PHP 的網頁截圖? (Web Page Screenshots with PHP?)

iPhone:如何在使用 3d 圖層轉換時以編程方式拍攝屏幕截圖 (iPhone: how to take screen shots programmatically when using 3d layer transformations)

防止 VideoView Activity 中的視頻屏幕截圖 - Android (Prevent Video screen capture in VideoView Activity - Android)







留言討論