PDA

View Full Version : Extracting data from web object



robmaggs
03-22-2007, 05:16 AM
Hi I'm working on a browser project with ams 5. I want the application to search for a string within the body of an online webpage (within a web object) and use that value for subsequent actions, does anyone have an ideas about how I could do this?

Process would be as follows:

User browses to web page, ams5 reads value from (page source) body of displayed page and stores value either to a string? or to a text file? and then retrieves the value when needed.

I can't define the webpage as a web address and download the webpage because the site uses a token to define the user/session and changes each time they log on.

Does anyone have any ideas about how I could do this?

Thanks in anticipation Rob :)

johnraus
03-22-2007, 04:10 PM
I had a similar, problem and got source with clipboard plugin

see this one: Get Source from Web, post28 (http://www.indigorose.com/forums/showpost.php?p=76506&postcount=28)

see entire tread for other solutions, thnx to Worm :cool

robmaggs
03-24-2007, 06:07 AM
Thanks johnraus for your help I'm still struggling though... :(


function GetSourceFromWeb(html) -- Retrieve Content from Embedded Web Object
-- if html is TRUE returns loaded HTML data
-- if html is FALSE returns loaded TEXT data

datastring = "";
local remember = "";
local rcount = 0;

if Clipboard.IsTextAvailable()
then
remember = Clipboard.GetText(); -- Only works with text on clipboard
Clipboard.CopyText("");
end;
Application.Sleep(10);
if html
then Web.LoadURL("Web1", "javascript:void(window.clipboardData.setData(\"Text\", document.body.createTextRange().htmlText));");
else Web.LoadURL("Web1", "javascript:void(window.clipboardData.setData(\"Text\", document.body.createTextRange().text));");
end;
repeat
Application.Sleep(10);
rcount = rcount +1;
until Clipboard.IsTextAvailable() or rcount==50;
if rcount < 50
then
datastring = Clipboard.GetText();
Application.Sleep(10);
Debug.Print("Get Source from Web O.K. "..rcount.."\r\n");
else
Debug.Print("Get Source from Web FAILED\r\n");
end;
Clipboard.CopyText(remember);

return datastring;

end;

I think this code from worm would do it but I'd like to then write the html to a local file on the hardrive afterward (or have a means of searching for a value within the source)

Any further ideas would be really appreciated.

Many thanks Rob :)

johnraus
03-24-2007, 09:31 AM
@robmaggs

I think you've made a few typo's,
clipboardData.setData(\"Te xt\" should be clipboardData.setData(\"Text\"


I had a similar, problem and got source with clipboard plugin
see this one: Get Source from Web, post28 (http://www.indigorose.com/forums/showpost.php?p=76506&postcount=28)

for my solution, Enable Clipboard Plugin, put above code in Global Functions

to get source to variable content

sSource = GetSourceFromWeb(true);

then

Dialog.Message("Page Source", sSource);
or
result = String.Find(sSource, "abcde", 1, false);
or
TextFile.WriteFromString("FileName", sSource, false);



for Worm's solutions look here (http://www.indigorose.com/forums/showthread.php?t=12414)

robmaggs
03-26-2007, 01:26 AM
Thanks Johnraus,

You are an absolute star, I was making a stupid mistake and not putting the code in the global settings. Thanks again for your help, I really appreciate it.

All the best Rob :)