Is it possible to get data (such a text or numbers)开发者_如何学JAVA from an application? For example when one's running an application the screen displays some text, images and numbers, would it be possible to code an automated procedure that would read that data (for the sake of saving it to an external file)?
you are refering to data scraping and the answer to your question is : yes you can do it... sometimes. it depends on the type of output your target application produces, and sometimes where it is outputs it to. If for example its plain text or HTML it relatively easy, if its bit maps its more complex.
so there is no general-solves-all solution, it depends on your setup.
You could take a screenshot. I imagine it would be a security problem to do what you describe. It used to be possible to read the actual text of password fields in other applications on older versions of Windows.
If it's Windows, there are lots of ways to do this, I've used many of them. (Haven't tried it on other platforms.)
The surest way at the moment is to use an Accessibility Hook (see http://msdn.microsoft.com/en-us/library/ms971310.aspx). Your program is essentially a 'screen reader', only instead of sending the text to a speech synthesizer you're saving it to a file.
I say that's "safest" because many of the other methods are used by malware, and so can set off alarms on the user's machine.
Note that some cases are harder than others. A java applet in a web browser is tough, for example.
I could go into more detail if I knew the nature of the app you're trying to scrape.
精彩评论