我想每小时打开相同的网址,并对已打开的网页进行屏幕截图

时间:2017-03-11 15:22:06

标签: applescript screen-capture

我想拍摄动态网页的截屏。内容每天都在变化。 我的脚本工作正常但是:  1.我希望确保脚本在iMac(OS X时)处于活动状态     Yosemite版本10.10.5)处于睡眠模式或屏幕保护程序处于活动状态时  2.第二个问题是屏幕截图必须是我想要的网页     而不是活动窗口。

set dFolder to "~/Desktop/screencapture/"
do shell script ("mkdir -p " & dFolder)
set i to 0
repeat 24 times
    do shell script "open -a Safari http://www.lipsum.com/"
    do shell script ("screencapture " & dFolder & "frame-" & i & ".png")
    delay 3600 -- Wait for 3600 seconds.
    set i to i + 1
end repeat

2 个答案:

答案 0 :(得分:1)

我不相信你可以用你选择的工具做你想做的事。我认为你需要使用webkit2png

转到GitHub并从here下载webkit2png脚本。它只是一个文件中的Python脚本。你需要在420行左右编辑它,看起来像这样(中间有3行):

# Hide the dock icon (needs to run before NSApplication.sharedApplication)
AppKit.NSBundle.mainBundle().infoDictionary()['LSBackgroundOnly'] = '1'

# Handles ATS HTTPS requirement introduced in El Cap
if options.ignore_ssl_check:
    AppKit.NSBundle.mainBundle().infoDictionary()['NSAppTransportSecurity'] = dict(NSAllowsArbitraryLoads = True)

app = AppKit.NSApplication.sharedApplication()

现在您可以下载您的网站,无论屏幕保护程序是否正在运行,无论使用哪个窗口,都可以使用:

./webkit2png --ignore-ssl-check -W 800 -H 600 -F -o MYSITE  http://www.lipsum.com/

您可以将其与现有的Applescript一起使用 - 只需将"frame-" & i放在MYSITE部分之后。

您可能需要输入完整路径而不是./webkit2png,因此,根据您保存脚本的位置,您可能需要使用类似/Users/Geonemec/webkit2png --ignore-ssl-check ...

的内容

您可以通过运行以下方式获得有关其接受的选项的帮助:

webkit2png -h

答案 1 :(得分:0)

set dFolder to "~/Desktop/screencapture/"

do shell script ("mkdir -p " & dFolder)

set i to 1
repeat 2 times
    set DeTijd to time string of (current date)
    tell application "Terminal"
        activate
        do script ("webkit2png --ignore-ssl-check -F -o PR" & DeTijd & " " & "http://www.google.com")
    end tell
    delay 3600 -- Wait for 3600 seconds = 1 hour.
    set i to i + 1
end repeat

这很好用。 Tx的帮助。