如何从 Linux 中的 GUI 应用程序中提取文本内容?
我想从 GUI 应用程序中提取文本内容,这里有 2 个示例::
示例 1:
假设我打开了 Firefox,并输入 url:www.google.com
我如何使用我的设备从 Firefox 中提取字符串“www.google.com”自己的应用程序?
示例2:
打开计算器(使用gcalctool),然后输入1+1
如何从我自己的程序中提取计算器的字符串“1+1”?
简而言之,我想要的是找出是否有一种方法可以从 GUI 应用程序的任何小部件中提取文本内容
谢谢
I want to extract text contents from GUI apps,here are 2 examples::
example 1:
Suppose I opened firefox, and input url : www.google.com
how can I extract the string "www.google.com" from firefox using my own app ?
example 2:
open calculator(using gcalctool),then input 1+1
How can I extract the string "1+1" of calculator from my own program?
in brief ,what I want is to find out whether there is a way to extract the text contents from any widget of an GUI application
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为没有一种通用的方法可以做到这一点,至少不是一种非常优雅的方法。
一些不雅的想法:
您也许可以修改 X 窗口系统甚至某些工具包框架来提取特定窗口元素中显示的内容作为文本。
您可以截取屏幕截图并使用 OCR 库将像素转换回有趣区域的文本。
您可以重新编译感兴趣的应用程序以添加某种向它们提问的机制。
您可以使用 xtest 之类的工具来注入突出显示感兴趣区域的事件并将其复制到剪贴板。
I don't think there's a generic way to do this, at least not a very elegant one.
Some inelegant ideas:
You might be able to modify the X window system or even some toolkit framework to extract what is being displayed in specific window elements as text.
You could take a screenshot and use an OCR library to convert the pixels back into text for the interesting areas.
You could recompile the apps of interest to add some kind of mechanism for asking them questions.
You could use something like xtest to inject events highlighting the region of interest and copying it to the clipboard.
我相信 firefox 和 gcalctool 仅作为示例,您只是想了解一般如何将一个应用程序的输出传递到另一应用程序。
在 Linux 上有很多方法可以做到这一点,例如:
管道
顺便说一句,这里是 Firefox命令行手册 如果您想通过 URL 在 Ubuntu 上启动 Firefox。例如:
其中 $url 是一个变量,其值可以是
www.mozilla.org
I believe firefox and gcalctool are for examples only and you just want to know in general how to pass output of one application to other application.
There are many ways to do that on Linux, like:
piping
btw here is the Firefox command line manual if you want to start firefox on Ubuntu with a URL. eg:
where $url is a variable whose value can be
www.mozilla.org
听起来很难。假设您正在运行 X11,您可以非常轻松地抓取窗口图片(请参阅“man xwd”);但是,除非选择文本并将其复制到剪贴板,否则没有简单的方法可以获取文本。
或者,如果您只想捕获用户输入,通过激活 X11 记录扩展也很容易做到:将其放入 /etc/X11/xorg.conf 中:
尽管它也可能很难使用,请参阅Xorg/X11 记录扩展失败的示例代码
That sounds difficult. Supposing you're running X11, you can very easily grab a window picture ( see "man xwd"); however there is no easy way to get to the text unless it's selected and therefore copied to the clipboard.
Alternatively, if you only want to capture user input, this is quite easy to do, too, by activation the X11 record extension: put this in your /etc/X11/xorg.conf:
though it may prove difficult to use too, see example code for Xorg/X11 record extension fails