views:

188

answers:

2

I want to scrape text data from a windows application to do additional processing using existing ruby code. Would it be possible to scrape the data as it is updated in the windows application using Ruby and where do I start?

+2  A: 

If you understand the Windows API well enough (or can use a search engine well enough to find the relevant APIs) then calling them from Ruby is generally achievable.

The Win32API library is the traditional way to access Windows APIs; there's also the sexy new FFI, although there may be outstanding issues regarding compiler as the MSVC6 to gcc transition rumbles on.

Mike Woodhouse
+1  A: 

If the text is in a standard windows control you can get at it with AutoIt. It's a scripting laguage of it's own and you can interact with it's functions in Ruby, like this:

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

This opens an instance of "Calc" and displays the content of the text control every second.

steenslag