从应用程序刮取屏幕 [英] Screen scraping from an application

查看:94
本文介绍了从应用程序刮取屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个vb.net应用程序,需要从中抓取数据.
源代码对我不可用(承包商对我们不可用-该应用程序是几年前开发的)

我正在编写一个C#应用程序,以从(该VB应用程序的)toolStrip上的特定toolStripLabel抓取.

当我使用Spy ++时,我可以看到有关ToolStrip的信息(句柄,标题,类,样式等)-但看不到包含我所需数据的toolStripLabel.


我正在用控制台应用程序测试我的概念,该应用程序将从我创建的非常快的VB表单中解析数据(转换为文本文件)
(包括工具条和toolStripLabel)-输出不包括工具条上的toolStripLabel.


我对使用"hWnd"并委托给"user32.dll"功能非常陌生,我所做的大部分工作都是基于我在论坛和MSDN文章中所看到的.


无论如何,我可以进一步深入ToolStrip以获得标签数据吗?
-还是有人可以建议我应该使用的委托函数?

我已经包含了我的输出-如您所见,找到了命令按钮和TooStrip文本-但没有找到toolStripLabel文本.

感谢您的任何建议或指点!


我的代码如下:

Hello all,

I have a vb.net application that I need to scrape data from.
The source code is not available to me (contractor not available to us - the application was developed several years ago)

I am writing a C# application to scrape from a particular toolStripLabel on a toolStrip (of that VB Application).

When I use Spy++ I can see the information for the ToolStrip (Handle, Caption ,Class , Style etc) - but it does not see the toolStripLabel that contains the data I need.


I am testing my concept with a console application that will parse the data (to a text file) out of a very quick VB Form that I created
(which includes a toolstrip and a toolStripLabel) - the output does not include the toolStripLabel on the toolstrip.


I am very new to using ''hWnd'' and delegate to the "user32.dll" functions and most of what I have done is based on what I have seen in forums and some MSDN articles.


Is there anyway that I can dip further into the ToolStrip to get the label data
- or can anyone suggest a delegate function that I should be using?

I have included my output - as you can see the command buttons and TooStrip text are found - but not the toolStripLabel text.

Thanks for any suggestions or pointers!


My code is as follows:

foreach (Process procesInfo in Process.GetProcesses())
{   
           
  if (procesInfo.ProcessName.ToString().Contains("testToolStrip"))
            {

                Console.WriteLine(procesInfo.ProcessName.ToString());
                Console.WriteLine("Target process found" + " " + procesInfo.ProcessName.ToString()   );

                foreach (ProcessThread threadInfo in procesInfo.Threads)
                {

                    IntPtr[] windows = GetWindowHandlesForThread(threadInfo.Id);
                    if (windows != null && windows.Length > 0)
                        foreach (IntPtr hWnd in windows)
                        {

                            System.IO.StreamWriter file = new System.IO.StreamWriter(@"c:\scrapeTest.txt", true);
                            file.WriteLine("\twindow {0:x} text:{1} caption:{2} xx:{3}", hWnd.ToInt32(), GetText(hWnd), GetEditText(hWnd), GetEditText(hWnd));
                            file.Close();

                }

               }

            }

}


它产生一个文本文件,其内容为:

窗口4f142c文本:Form1标题:xx:
窗口6414e4文本:Button2标题:Button2 xx:Button2
窗口74154e文本:Button1标题:Button1 xx:Button1
窗口1d1458文本:我是toolStrip文本标题:我是toolStrip文本xx:我是toolStrip文本
窗口4d14a0文本:.NET-BroadcastEventWindow.4.0.0.0.2bf8098.0标题:xx:
窗口4a14ea文本:M标题:xx:
视窗33153c文字:预设输入法标题:xx:
窗口27147c文本:GDI +窗口标题:xx:
窗口531430文本:默认IME标题:xx:


It produces a textfile with the contents:

window 4f142c text:Form1 caption: xx:
window 6414e4 text:Button2 caption:Button2 xx:Button2
window 74154e text:Button1 caption:Button1 xx:Button1
window 1d1458 text:I am the toolStrip text caption:I am the toolStrip text xx:I am the toolStrip text
window 4d14a0 text:.NET-BroadcastEventWindow.4.0.0.0.2bf8098.0 caption: xx:
window 4a14ea text:M caption: xx:
window 33153c text:Default IME caption: xx:
window 27147c text:GDI+ Window caption: xx:
window 531430 text:Default IME caption: xx:

推荐答案

为什么不使用CFF资源管理器搜索toolstriplabel的内容.
我重新创建了您的问题,发现exe在
处具有toolstriplabel文本值 (在CFF Explorer中)
.NET目录-> MetaData流-&#;#US


在那里,您将看到toolstriplabel1,然后在ascii窗格中看到标签文本....
Why dont you use CFF explorer to search the content of toolstriplabel.

I recreated your issue and saw that exe has got the toolstriplabel text value at
(In CFF Explorer)
.NET Directory->MetaData streams->#US


There you''ll see toolstriplabel1 and then the label text in ascii pane....


只有一种方法不会危害您的业务:承认公司丢了工作,一分钱不付钱,并执行一些健康的代码所有权惯例.至于源代码不可用"给您,则永远不要使用它,而应该创建一个新的源代码.

我想像一下,使用无法支持的程序会比编写新程序获得更多资源,因为我从我的经验中知道这一点.

我绝对是认真的:使用您无法支持的程序是浪费的,而且最重要的是,它非常危险.有人犯了一个大错误并丢失了代码,因此该人应对失败负责.

抱歉,如果您认为这样做没有帮助.这样想:我只是在帮助您避免使情况变得更糟.您的屏幕抓取"越成功,对公司的危害就越大.如果您的公司组织和人员没有能力通过更好的管理决策来解决这种情况,那么我不想让您失望,但是您应该意识到公司无处可去,麻烦很快就会到来;所以我会认真建议寻找替代工作.是的,认真.

—SA
There is only one way which would not endanger your business: admit that the company lost the work and payed money for nothing and implement some healthy code ownership practices. As to the "source code is not available to" you, it should never be used, and a new one should be created.

I would imaging that using the program which you cannot support could get more resources than writing a new program, because I know this from my experience.

I''m absolutely serious: using the program which you cannot support is wasteful and, most importantly, very dangerous. Somebody made a big mistake and lost the code, so this person should take the responsibility for the failure.

Sorry if you think this does not help you. Think of it this way: I''m just trying to help you to avoid making things worse. The more successful your "screen scraping", the more harm to your company. If your company organization and people are not capable to fix this situation through better management decisions, I don''t want to discourage you, but you should realize that the company goes nowhere, and the troubles could come soon; so I would seriously advise to look for alternative job. Yes, seriously.

—SA


我不会在此浪费时间.就像SAK所说的那样,即使使用该应用程序也是一个危险的举动,更不用说从中进行抓取了.

首先,此应用程序是否经过完整测试?有没有错误?是否有可能应用新功能或错误修复程序?不!

无论发生什么情况,您都必须从头开始重写此野兽,从而使您的抓取应用程序无法使用,因为在您使用它的同时,您还可以使用可通过文件或文件导出数据的功能.一些远程接口.
I wouldn''t waste my time on this. Like SAK said, even using that app is a dangerous move, let alone scraping from it.

First, is this app COMPLETELY tested?? Are there any bugs? Is there any chance of new features or bugs fixes being applied?? Nope!

No matter what happens, you''re going to have to rewrite this beast from scratch, thereby making your scraping app useless since, while you''re at it, you may as well put in features that can export data through either files or some remotable interface.


这篇关于从应用程序刮取屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆