【问题标题】:Taking Screenshot of firefox webpage using shell scripting使用 shell 脚本截取 firefox 网页截图
【发布时间】:2021-06-22 00:49:48
【问题描述】:

我有一些函数在 Unix 终端中运行。在那个功能中 - 我想合并这个实用程序。我想使用 shell 脚本截取 Firefox 网页的屏幕截图。例如 - 在该函数中,正在生成一些 HTML 文件。我必须使用 shell Cmd 在 Firefox 中打开该 HTML 文件,然后我必须将其设为全屏并截取该 Firefox 窗口的屏幕截图,但这里要注意的是 - 我有多个窗口运行相同的功能。所以如果我使用该功能同时在不同的终端中 - 将打开多个 Firefox,并且没有正确截屏。另外,我想在这里提一下——我在 Unix 中尝试过 xdotool,但有时你会收到以下错误消息。

我正在使用的脚本

set window_id [ xdotool search --pid $pid --name "firefox" | tail -1]
xdotool search --onlyvisible --class "firefox" set_window $window_id windowraise
xdotool search --onlyvisible --class "firefox" set_window $window_id key F11
sleep 3
xdotool search --onlyvisible --class "firefox" set_window $window_id windowraise
sleep 2
import -window $window_id ~/image.jpg
xdotool windowactivate --sync $window_id
xdotool search --onlyvisible --class "firefox" set_window $window_id windowraise
xdotool search --onlyvisible --class "firefox" set_window $window_id key ctrl+q
sleep 0.1

使用 shell 打开 Firefox - 我正在使用以下行

/usr/pkgs/firefox/bin/firefox --setDefaultBrowser --new-instance ~/test.html

另外,我想在这里提一下——我在 UNIX 中尝试过 xdotool 但有时我会收到以下错误消息 -

失败请求的X错误:BadWindow(无效的Window参数)

【问题讨论】:

  • 考虑使用 selenium 之类的东西

标签: python linux shell


【解决方案1】:

这是一个可行的解决方案。

sudo apt-get install xautomation

sudo apt-get install gnome-screenshot

xte 'keydown Alt_L' 'key Tab' 'keyup Alt_L' 'key Tab`(send as many tabs as windows switchs)
gnome-screenshot

您可以将其保存为.sh 文件并运行它。

【讨论】:

    猜你喜欢
    • 2022-10-14
    • 2010-09-08
    • 2013-06-15
    • 2011-01-19
    • 1970-01-01
    • 2011-10-25
    • 1970-01-01
    • 2018-06-19
    相关资源
    最近更新 更多