创建网站截图的命令行程序(在 Linux 上)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/125951/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Command line program to create website screenshots (on Linux)
提问by ujh
What is a good command line tool to create screenshots of websites on Linux? I need to automatically generate screenshots of websites without human interaction. The only tool that I found was khtml2png, but I wonder if there are others that aren't based on khtml (i.e. have good JavaScript support, ...).
在 Linux 上创建网站截图的好命令行工具是什么?我需要在没有人工交互的情况下自动生成网站截图。我发现的唯一工具是khtml2png,但我想知道是否还有其他工具不是基于 khtml 的(即具有良好的 JavaScript 支持,...)。
采纳答案by Shannon Nelson
A little more detail might be useful...
多一点细节可能有用...
Start a firefox (or other browser) in an X session, either on your console or using a vncserver. You can use the --height
and --width
options to set the size of the window to full screen. Another firefox command can be used to set the URL being displayed in the first firefox window. Now you can grab the screen image with one of several commands, such as the "import" command from the Imagemagick package, or using gimp, or fbgrab, or xv.
在控制台或使用 vncserver 的 X 会话中启动 firefox(或其他浏览器)。您可以使用--height
和--width
选项将窗口大小设置为全屏。另一个 firefox 命令可用于设置在第一个 Firefox 窗口中显示的 URL。现在,您可以使用多个命令之一抓取屏幕图像,例如 Imagemagick 包中的“import”命令,或者使用 gimp、fbgrab 或 xv。
#!/bin/sh
# start a server with a specific DISPLAY
vncserver :11 -geometry 1024x768
# start firefox in this vnc session
firefox --display :11
# read URLs from a data file in a loop
count=1
while read url
do
# send URL to the firefox session
firefox --display :11 $url
# take a picture after waiting a bit for the load to finish
sleep 5
import -window root image$count.jpg
count=`expr $count + 1`
done < url_list.txt
# clean up when done
vncserver -kill :11
回答by Paul Whelan
I know its not a command line tool but you could easily script up something to use http://browsershots.org/Not that useful for applications not hosted on external IPs.
我知道它不是命令行工具,但您可以轻松编写一些脚本以使用http://browsershots.org/对未托管在外部 IP 上的应用程序没有那么有用。
A great tool none the less.
一个很棒的工具。
回答by Jim T
I don't know of anything custom built, I'm sure there could be something done with the gecko engine to render to a png file instead of the screen ...
我不知道任何定制的东西,我相信壁虎引擎可以做一些事情来渲染到 png 文件而不是屏幕......
Or, you could fire up firefox in full screen mode in a dedicated VNC server instance and use a screenshot grabber to take the screenshot. Fullscreen = minimal chrome, VNC server instance = no visible UI + you can choose your resolution.
或者,您可以在专用 VNC 服务器实例中以全屏模式启动 firefox,并使用屏幕截图抓取器进行屏幕截图。全屏 = 最小的 chrome,VNC 服务器实例 = 没有可见的 UI + 你可以选择你的分辨率。
Use xinit with Xvnc as the X server to do this - you'll need to read all the manpages.
使用 xinit 和 Xvnc 作为 X 服务器来执行此操作 - 您需要阅读所有联机帮助页。
Downsides are that the screenshot is always the same size, doesn't resize according to the web page ...
缺点是屏幕截图总是相同的大小,不会根据网页调整大小......
回答by Andrea Ambu
There is the importcommand, but you'll need X, and a little bash script that open the browser window, then take the screenshot and close the browser.
有导入命令,但您需要 X 和一个打开浏览器窗口的小 bash 脚本,然后截取屏幕截图并关闭浏览器。
You can find more information here, or just typing import --helpin a shell ;)
你可以在这里找到更多信息,或者在 shell 中输入import --help;)
回答by Hamish Downer
scrotis a command line tool for taking screenshots. See the man pageand this tutorial.
scrot是用于截取屏幕截图的命令行工具。请参阅手册页和本教程。
You might also want to look at scripting the browser. There are firefox add-ons that take screenshots such as screengrab(which can capture the entire page if you want, not just the visible bit) and you could then script the browser with greasemonkeyto take the screenshots.
您可能还想查看编写浏览器的脚本。有一些 firefox 插件可以截取屏幕截图,例如screengrab(如果需要,它可以捕获整个页面,而不仅仅是可见的部分),然后您可以使用greasemonkey编写浏览器脚本来截取屏幕截图。
回答by Stephan Wehner
http://khtml2png.sourceforge.net/
http://khtml2png.sourceforge.net/
The deb file
deb 文件
worked on my Ubuntu after installing libkonq4 ... but you may have to cover other dependencies.
安装 libkonq4 后在我的 Ubuntu 上工作......但你可能需要覆盖其他依赖项。
I think javascript support may be better now!
我认为现在对 javascript 的支持可能会更好!
Stephan
斯蒂芬
回答by SLN
Not for the command line but at least for usage in batch operation for a larger set of urls you may use firefox with its addon fireshot (licensed version?).
不是用于命令行,而是至少用于批量操作以用于更大的一组 url,您可以使用 firefox 及其插件 fireshot(许可版本?)。
- Open tabs for all urls in your set (e.g. "open tabs for all bookmarks in this folder...").
- Then in fireshot launch "Capture all tabs"
- In the edit window then call "select all shots -> save all shots"
- 打开您集合中所有 url 的标签(例如“打开此文件夹中所有书签的标签...”)。
- 然后在 fireshot 中启动“捕获所有标签”
- 在编辑窗口中,然后调用“选择所有镜头-> 保存所有镜头”
Having set the screenshot properties (size, fileformat, etc.) before you end with a nice set of shotfiles.
设置好截图属性(大小、文件格式等),然后再用一组漂亮的截图文件结束。
Steffen
史蒂芬
回答by m7n7
回答by Luke H
See Webkit2png.
参见Webkit2png。
I think this is what I used in the past.
我认为这是我过去使用的。
EditI discover I haven't used the above, but found this pagewith reviews of many different programs and techniques.
编辑我发现我没有使用上述内容,但发现此页面包含对许多不同程序和技术的评论。
回答by MaxiWheat
Have a look at PhantomJS, which seems to be a free scritable Webkit engine that runs on Linux, OSX and Windows. I've not used it since we currently use Browshot(commercial solution), but when all our credits run out, we will seriously have a loot at it (since it's free and can run on our servers)
看看PhantomJS,它似乎是一个免费的可编写脚本的 Webkit 引擎,可在 Linux、OSX 和 Windows 上运行。我没有使用它,因为我们目前使用Browshot(商业解决方案),但是当我们所有的积分用完时,我们将认真对待它(因为它是免费的并且可以在我们的服务器上运行)