ivan Posted November 23, 2005 Share Posted November 23, 2005 (edited) I'm using a modified version of IE.au3 with the following addition to _IEAttach which Dale was kind enough to supply me with, and which is going into the next update of IE.au3: Case $s_mode = "hwnd" If _IEGetProperty($o_window, "hwnd") = String($s_string) Then SetError(0) Return $o_window EndIf which I use to retreive the object reference to an open IE explorer browser window. I wish to retreive a table within a table say, the contents of className2 in the following theoretical example: <table attributes.... class="className1"> <table attributes.... class="className2"> ... </table> </table> In reality the tables I'm concerned with are embeded within other tables, but this should be sufficient for the explanation. I wondered if I can pull out the content of <table attributes.... class="className2"> without having to go through a table count and check each table as I do below. I managed to retreive the table I want with the following code: ; get the browser object reference $oBrowser = _IEAttach ($ActiveBrowserHandle, "hwnd") ;count the number of tables in object $oBrowser $NumTables = _IETableGetCount ($oBrowser) ; walk through the tables For $i = 1 To $NumTables $oTable = _IETableGetObjByIndex ($oBrowser, $i) $TableArray = _IETableWriteToArray ($oTable) $Dim = UBound($TableArray, 0) $Rows = UBound($TableArray) $Cols = UBound($TableArray, 2) ; create a handle to check in a text file what was retreived from the table $TableNum= "Table " &$i If $Rows>0 Then For $n=0 To ($Rows-1) Step 1 If $Cols>0 Then For $m=0 To ($Cols-1) Step 1 ; Table $i=1 doesn't contain the info I want and table $i=2 contains all the tables, including the one i'm interested in. However, I want just the text contained in table $=19, but this could vary according to what the user has selected. Therefore, I need to check tables $i>2. Now the Search criteria is a the table heading, which fortunately is unique to the table If StringInStr($TableArray[$n][$m], "UNIQUE TABLE HEADING TEXT") And $i>2 Then ; I output the content of the table I want to a text file and I'm done FileWriteLine($TableNum & ".txt", "Dim [" &$n &"][" &$m &"]: " & $TableArray[$n][$m] & @CRLF) EndIf Next EndIf Next If any of you wizzards has come accross something like this before, I'd be really grateful if you could share your solution with me. I doubt you are really interested in mine, as it's long and takes a lot of processing on the machine's behalf. I forgot to be polite and say thanks for reading this. Edited November 23, 2005 by ivan Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 Link to comment Share on other sites More sharing options...
DaleHohm Posted November 23, 2005 Share Posted November 23, 2005 There are lots of different properties you can look for on a table (see here) including className -- so if you are looping through all of the tables in the table collection you can check to see which one has the attributes you are looking for. For example, you can check If $oTable.className = "classname2" and then process that table when you find it.Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
ivan Posted November 23, 2005 Author Share Posted November 23, 2005 Wow, Dale again. At this rate I'm going to owe you more than a beer. Thanks. Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 Link to comment Share on other sites More sharing options...
ivan Posted November 23, 2005 Author Share Posted November 23, 2005 I got it working perfectly thanks to Dale. In case there's people interested, this is more or less how it goes so far: classNameToSearch obviously will have to be replaced. $oBrowser = _IEAttach ($ActiveBrowser[0], "hwnd") $TableGetCollection = _IETableGetCollection ($oBrowser) If IsObj($TableGetCollection) Then For $oTable In $TableGetCollection If $oTable.className = "classNameToSearch" Then $TableArray = _IETableWriteToArray ($oTable) $Dim = UBound($TableArray, 0) $Rows = UBound($TableArray) $Cols = UBound($TableArray, 2) If $Rows > 0 Then For $n = 0 To ($Rows - 1) Step 1 If $Cols > 0 Then For $m = 0 To ($Cols - 1) Step 1 FileWriteLine("Table.txt", "Dim [" & $n & "][" & $m & "]: " & $TableArray[$n][$m] & @CRLF) Next EndIf Next EndIf EndIf Next EndIf I believe I can optimize this much further, so don't be surprised If I add something in the next few minutes. Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now