我想从 Windows 应用程序中抓取文本数据,以使用现有的 ruby 代码进行其他处理。是否可以使用 Ruby 在 Windows 应用程序中更新数据时抓取数据?我从哪里开始?
最佳答案
如果文本位于标准 Windows 控件中,您可以使用 AutoIt 获取它。它是它自己的脚本语言,您可以在 Ruby 中与其函数进行交互,如下所示:
require 'win32ole'
STDOUT.sync = true
App = "calc.exe"
AppClass = "[CLASS:SciCalc]" # retrieved with AutoIt Window Info
ai = WIN32OLE.new("AutoItX3.Control")
ai.run( App )
ai.winwaitactive( AppClass )
handle = "[HANDLE:#{ai.wingethandle(AppClass)}]"
until ai.winexists( handle ).zero?
puts ai.controlgettext( handle, "", "Edit1" ) # retrieved with AutoIt Window Info
sleep 1
end
这将打开一个“Calc”实例并每秒显示文本控件的内容。
关于windows - 是否可以使用 ruby 来抓取 Windows 应用程序的屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2590475/