Jump to content

Read website text within frames?


Burgs
 Share

Recommended Posts

Hello,

I'm using the following code in an attempt to read information from a website (stock symbols with prices). It partly works however there are 2 main issues I've identified so far:

1. If the desired stock symbol to find (CAT in my example) appears in the "visible" area of the screen it seems to be located without difficulty, however if it is further down the frame list (requiring a "scroll down") then it is NOT found by the code.

2. The "FileReadLine" doesn't appear to return the line of text the for the stock symbol even if in an area of the screen where the code can find it...the "ConsoleWrite" does not output anything.

I'd like to be able to simply output the table contents of the website to an array, however this website in question doesn't seem to have any tables, just a few frames...I don't believe it's possible to output the frame info into an array as it would be possible with tables.

Any help with resolving these issues is greatly appreciated, it would be neat to be able to pull intraday financial information in an automated fashion...Thank you in advance.

#include <Array.au3>

#include <IE.au3>

$oIE = _IECreate ("http://www.freestockcharts.com/")

_IELoadWait ($oIE)

$oFrames = _IEFrameGetCollection ($oIE)

$iNumFrames = @extended

For $i = 0 to ($iNumFrames - 1)

$oFrame = _IEFrameGetCollection ($oIE, $i)

$sHTML = _IEBodyReadHTML ($oFrame)

$locater = StringInStr($sHTML, "CAT")

if $locater > 0 Then

MsgBox(4096, "Status", "Found IT!!!", 10)

$locater2 = FileReadLine($sHTML, $locater)

ConsoleWrite($locater2)

EndIf

Next

Link to comment
Share on other sites

StringInStr() returns a character position, not a line number. And you can't pass multi-line string data into FileReadLine() and read a line out of it.

You could probably do StringInStr(), then use StringMid() to get just the part from there on, and StringSplit() to break that into lines.

A better choice might be to get a collection of the elements you are looking for and loop through them to fine the one you want, then work from there to get the other TD tags in the same TR, or whatever it takes to find what you are really looking for.

For that matter, if it's all in one or more tables, you could just read the table to an array with _IETableReadToArray() and work with that.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks for the reply. Can you please explain what you mean by "TD" and "TR" values? I don't understand those abbreviations, please forgive me.

If the website was broken into tables I could use that to my advantage as you had suggested, however there are only frames...is it possible to loop thru the elements of a frame in a similiar way as one would do for a table??

Link to comment
Share on other sites

TR and TD are "table row" and "table data" elements used in an HTML table. Time to learn what a web page looks like inside the browser. The web document is presented as a Document Object Model (DOM). The whole point of the IE.au3 UDF is for working with the IE DOM.

You can view the DOM with a browser plug-in called a DOM Inspector. For IE, DebugBar gets mentioned the most around here. Using a DOM Inspector, you'll be able to drill down into the elements in the frames, and figure out what you want (i.e. table names or IDs).

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...