Burgs Posted February 23, 2011 Share Posted February 23, 2011 Hello, I'm wondering if there is a way to use the either/or the FileReadLine or StringInStr commands to search for text that is formatted in columns? I'm simply trying to capture the text on a webpage that is formatted in a table, with the information I desire located in columns in the middle of the page continuing downwards towards the bottom...possible? Thank you in advance for any advice... Link to comment Share on other sites More sharing options...
willichan Posted February 23, 2011 Share Posted February 23, 2011 Are the columns in fixed character positions, tab delimited, or some other format? My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash Link to comment Share on other sites More sharing options...
Burgs Posted February 23, 2011 Author Share Posted February 23, 2011 Are the columns in fixed character positions, tab delimited, or some other format?Hi, I wish they were tab delimited, however they are not. They are more or less in fixed positions under the "heading" of the column but the exact positioning can change a bit on differing web pages... Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 23, 2011 Share Posted February 23, 2011 _IETableWriteToArray() See help file. 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 More sharing options...
Burgs Posted February 23, 2011 Author Share Posted February 23, 2011 Thanks I took a look at that command and it seems it loads the entire table as a 2D array...I'm only interested in 1 particular column of the table...so that command is not applicable unless there's a way to "strip out" the only column I'm interested in...?? Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 23, 2011 Share Posted February 23, 2011 (edited) Depends on how you were going to use the data afterwords. First note the row/col order of the received array, it might not be what you expected. "TR" tags become columns, and "TD" tags become rows unless you set the $f_transpose flag in _IETableWriteToArray(). So if you intend to just loop through the data and do something with it, just loop through the array incrementing only the row or col index as required and leaving the other one fixed. If you must have it as a 1-D array, the do a quick loop to move the required data to a new array. At that point it is all happening inside AutoIt memory space and will be VERY fast anyway. #include <IE.au3> #include <Array.au3> $oIE = _IE_Example ("table") $oTable = _IETableGetCollection ($oIE, 0) $aData = _IETableWriteToArray($oTable) ; Just use the array as-is For $n = 0 To UBound($aData, 2) - 1 ; Get third column of each row of the HTML table $sData = $aData[2][$n] ConsoleWrite("[2][" & $n & "] = " & $sData & @LF) Next ; -- or -- ; Copy data to another array Global $aColData[UBound($aData, 2)] For $n = 0 To UBound($aData, 2) - 1 ; Get third column of each row of the HTML table $aColData[$n] = $aData[2][$n] Next _ArrayDisplay($aColData, "Col Data") Edit: Added example. Edited February 23, 2011 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 More sharing options...
Burgs Posted February 23, 2011 Author Share Posted February 23, 2011 (edited) I'll play around with it when I have the chance. Thank you for the responses...as well as the code, it's much appreciated. Edited February 23, 2011 by Burgs Link to comment Share on other sites More sharing options...
Burgs Posted February 24, 2011 Author Share Posted February 24, 2011 Hello, I've got a follow-up question, using the following code: $oTable = _IETableGetCollection ($oIE) $iNumTables = @extended MsgBox(0, "Table Info", "There are " & $iNumTables & " tables on the page") Upon running this code the message box reports the website in question has "18 tables"...my question is how do I determine which is the table I wish to use/capture the data to the array? Using the AutoIT Window Info Tool has not revealed any worthwhile info about the tables on the website. Thanks in advance. Link to comment Share on other sites More sharing options...
EvilEd Posted February 24, 2011 Share Posted February 24, 2011 (edited) I like using the following code the first time I'm reading a table: $oTables = _IETableGetCollection($oIE) For $oTable In $oTables $aTableData = _IETableWriteToArray($oTable) _ArrayDisplay($aTableData) Next This will show you how the data will look in an array. Usually the first row is a descriptive header that can be useful for the program to determine the correct table to use. If you are always going to use just one table, then use the _IETableGetCollection() index parameter to get just that table instead of the collection of tables. I like using this _IETableWriteToArray() and _ArrayDisplay() combination to visualize the data even if I'm not planning to use an array in the final code. Edited February 24, 2011 by EvilEd Link to comment Share on other sites More sharing options...
Burgs Posted February 24, 2011 Author Share Posted February 24, 2011 Thanks for that info, that code is pretty useful. Using that code I can see each table on the website display it's held information and I can see that I'm actually looking for a particular "row" in the table and not a column as I had previously thought. I still however don't understand how to "direct" AutoIT to write the "correct" table since that code is holding/displaying 18 different tables within...please forgive me I've never used arrays with AutoIT before. Link to comment Share on other sites More sharing options...
GEOSoft Posted February 24, 2011 Share Posted February 24, 2011 (edited) Can you provide a link to the page? It can possibly be done with a regular expression.Edit: If you can't provide the link then post that portion of the page source that contains the table you are interested in and a few lines on both sides of it. Edited February 24, 2011 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
EvilEd Posted February 24, 2011 Share Posted February 24, 2011 Thanks for that info, that code is pretty useful. Using that code I can see each table on the website display it's held information and I can see that I'm actually looking for a particular "row" in the table and not a column as I had previously thought. I still however don't understand how to "direct" AutoIT to write the "correct" table since that code is holding/displaying 18 different tables within...please forgive me I've never used arrays with AutoIT before. Oh sorry. To transpose the rows and columns use _IETableWriteToArray($oTable, True). I'm not sure what you are trying to do. Are you using only one of the 18 tables or more than one? Have you figured out how to identify (in code) which table you need? If you are just using the 4th table then just get one array like this: $oTable = _IETableGetCollection($oIE, 3) ; The index is zero based, so the 4th table is index 3. $aTableData = _IETableWriteToArray($oTable, True) ; Added 2nd parameter to transpose row/column For $i = 0 To UBound($aTableData, 1) - 1 If $aTableData[$i][0] = "State:" Then $State = $aTableData[$i][1] Endif Next MsgBox(0, "State", $State) Link to comment Share on other sites More sharing options...
Burgs Posted February 24, 2011 Author Share Posted February 24, 2011 OK thanks again, I think I've got it narrowed down a bit. Yes I'm only using 1 table, it turns out I want table #16 out of the 18 on the page and I believe I've got it correctly assigned ($oTable = _IETableGetCollection($oIE, 15)...). Thanks for your patience, it's appreciated. 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