|
-
Mar 14th, 2006, 09:11 AM
#1
Thread Starter
New Member
Screen Scraping Windows Applications
Hello,
Using vs 2003, vb.net as a windows application....how would I go about scraping information from a specific window when there could be multiple windows open from various apps. I need to identify the proper window and then scrape 3 fields of information off the screen and place them into text boxes on my own application that would be open at the time?
1. my application would be open (windows app)
2. user clicks 'get data' button
3. program somehow iterates through all open windows and selects the window that I need to scrape
4. the data is scraped from this window (3 separate fields) and these fields are placed into 3 separate text boxes in my app.
I believe the windows I'm scraping the info from would be another windows app...this may end up being some kind of terminal emulation program or something...
Anyone have any ideas?
Thanks in advance for any help you can offer me.
Scott
-
Mar 14th, 2006, 09:54 AM
#2
New Member
Re: Screen Scraping Windows Applications
windows screen scraping is a VERY difficult endeavor. You can use tools like AutoIt to determine which window by the window title or text in the window. To actually get data off the screen will depend what the app is. I don't relish your task.
-
Mar 14th, 2006, 12:53 PM
#3
Re: Screen Scraping Windows Applications
I found an example from microsoft before that had a screen scraping example in a Regular Expressions sample app, I had modified it a little so I dont have the original project anymore, and not sure if it even works. I tried searching for it but was unable to find it again. Here is the assembly information if you wish to try to search...
Code:
<Assembly: AssemblyTitle("VB.NET How-To: Use Regular Expressions")>
<Assembly: AssemblyDescription("Microsoft Visual Basic .NET How-To: Use Regular Expressions")>
<Assembly: AssemblyCompany("Microsoft Corporation")>
<Assembly: AssemblyProduct("Microsoft Visual Basic .NET How To: 2002")>
<Assembly: AssemblyCopyright("Copyright © 2002 Microsoft Corporation. All rights reserved.")>
<Assembly: CLSCompliant(True)>
**Note - I believe it was to scrape downloaded HTML code...
**EDIT - This might be it, but I havent downloaded it to check...
-
Mar 14th, 2006, 01:17 PM
#4
Re: Screen Scraping Windows Applications
Actually, this isn't all that hard, but it sure can be tricky. You will need to use API calls, here they are:
VB Code:
Declare Ansi Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Declare Ansi Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Integer, ByVal lpString As System.Text.StringBuilder, ByVal nMaxCount As Integer) As Integer
Declare Ansi Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWndParent As Integer, ByVal hWndChildAfter As Integer, ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Declare Ansi Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA" (ByVal hWnd As Integer, ByVal msg As Integer, ByVal buffSize As Integer, ByVal lParam As System.Text.StringBuilder, ByVal fuFlags As Integer, ByVal uTimeout As Long, ByVal lpdwResult As Integer) As Integer
Also, here's a snippet showing how I go after a specific window in a program:
VB Code:
Private Function FindProg() As Boolean
Dim lClientHandle As Integer
Dim lH As Integer
Dim lH2 As Integer
Dim tWin1 As Integer
Dim x As Integer
Dim st1 As String
Dim stBuilder As New System.Text.StringBuilder(256)
Try
'Get the top level window using the window caption.
p3Handle = FindWindow(vbNullString, "PITTag3 - [New Tag Session]")
If p3Handle = 0 Then
'This is another possibility.
p3Handle = FindWindow(vbNullString, "PITTag3")
If p3Handle = 0 Then
'This is an attempt to find the registered class.
p3Handle = FindWindow("ThunderRT6MDIForm", vbNullString)
If p3Handle > 0 Then
x = GetWindowText(p3Handle, stBuilder, stBuilder.Capacity + 1)
'This would be the right one.
st1 = stBuilder.ToString
If Not st1.Substring(0, 7) = "PITTag3" Then
mErrorMessage = "Some other program is blocking the visibility of P3."
Return False
End If
End If
End If
End If
If p3Handle > 0 Then
'The rest of these lines drill down through the many layers of client windows
'to get the handle of the base window.
lClientHandle = FindWindowEx(p3Handle, 0, "MDIClient", vbNullString)
lH2 = FindWindowEx(lClientHandle, 0, "ThunderRT6FormDC", vbNullString)
If lH2 = 0 Then
mErrorMessage = "There is no session open. Try this again after opening a session."
Return False
End If
lH = FindWindowEx(lH2, 0, vbNullString, vbNullString)
lH2 = FindWindowEx(lH, 0, vbNullString, vbNullString)
lH2 = FindWindowEx(lH, lH2, vbNullString, vbNullString)
tWin1 = FindWindowEx(lH2, 0, "ATLfpOCXComboBox30", vbNullString)
For x = 1 To 3
tWin1 = FindWindowEx(lH2, tWin1, "ATLfpOCXComboBox30", vbNullString)
Next
'This is the proper window, so use it.
p3TextHandle = FindWindowEx(lH2, tWin1, "ATLfpOCXComboBox30", vbNullString)
If p3TextHandle = 0 Then
mErrorMessage = "Unable to find the correct textbox. This is hard to explain, but if you get this message, there is still a bug remaining to be squashed."
Return False
Else
Return True
End If
Else
mErrorMessage = "P3 could not be located. It may not be running, or some unforseen situation has arisen."
Return False
End If
Catch ex As Exception
mErrorMessage = ex.Message
Return False
End Try
End Function
Look up the API calls in MSDN for more information about what they do. Then use Spy++ to look at the window you are looking for. There is a little bullseye tool in Spy++ that can show you information about a specific window, but I found it to be generally more usefull to look at a list of all running programs. The thing is that there might be more than one registered window with the same class name and window name, but you will find that the one you want is always in the same relationship to others. The Find Prog function should show you how I did that for a specific window in a specific program.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|