如何通过 bash 或 python 从最活跃的 firefox 浏览器选项卡中获取页面标题,从 firefox 获得焦点?
How to get page title from most actice firefox browser tab by bash or python, from firefox which is in focus?
如何通过bash或python从firefox的大多数actice选项卡中获取页面标题?
下面的部分解决方案,展示了如果只打开一个 Firefox window 如何做到这一点。 (如果打开了多个 FF windows,则此部分解决方案无法执行此操作。此部分解决方案仅检查一个 运行 FF window 中最活跃的选项卡,或者如果更多比一个 ff window 打开,最活跃的选项卡,从第一个开始 FF window.).
部分bash解决方案:
var=$(wmctrl -l -p | grep Firefox)
echo "$var"
部分Python解决方案:
import subprocess
wins = subprocess.run('wmctrl -l', shell=True, stdout=subprocess.PIPE)
title = next(ln for ln in wins.stdout.decode('utf-8').splitlines() if 'Mozilla Firefox' in ln)
print title
备注:
A solution in bash or Python is sought, but not one that requires the installation of a browser addon, based on Javascript, Selenium or Brotab.
xdotool可以得到当前有焦点的window,假设这是你要跟踪的Firefox实例:
$ active_window_id=$(xdotool getwindowfocus)
$ xdotool getwindowname $active_window_id
或更短:
$ xdotool getwindowfocus getwindowname
如何通过bash或python从firefox的大多数actice选项卡中获取页面标题?
下面的部分解决方案,展示了如果只打开一个 Firefox window 如何做到这一点。 (如果打开了多个 FF windows,则此部分解决方案无法执行此操作。此部分解决方案仅检查一个 运行 FF window 中最活跃的选项卡,或者如果更多比一个 ff window 打开,最活跃的选项卡,从第一个开始 FF window.).
部分bash解决方案:
var=$(wmctrl -l -p | grep Firefox)
echo "$var"
部分Python解决方案:
import subprocess
wins = subprocess.run('wmctrl -l', shell=True, stdout=subprocess.PIPE)
title = next(ln for ln in wins.stdout.decode('utf-8').splitlines() if 'Mozilla Firefox' in ln)
print title
备注:
A solution in bash or Python is sought, but not one that requires the installation of a browser addon, based on Javascript, Selenium or Brotab.
xdotool可以得到当前有焦点的window,假设这是你要跟踪的Firefox实例:
$ active_window_id=$(xdotool getwindowfocus)
$ xdotool getwindowname $active_window_id
或更短:
$ xdotool getwindowfocus getwindowname