VinodKP Posted August 10, 2009 Posted August 10, 2009 Hi, Is there an alternate for _IETableGetCollection?
Juvigy Posted August 10, 2009 Posted August 10, 2009 Yes,try this #include <IE.au3> $oIE=_IECreate("somesite") $oDoc = _IEDocGetObj($oIE) $oArray = $oDoc.getElementsByTagName ("td")
VinodKP Posted August 10, 2009 Author Posted August 10, 2009 (edited) Yes,try this #include <IE.au3> $oIE=_IECreate("somesite") $oDoc = _IEDocGetObj($oIE) $oArray = $oDoc.getElementsByTagName ("td") Hi, Thanks for the quick reply. But using _IECreate function is slower as compared to InetGet, I am looking for an alternative wherein I don't have to use Internet Explorer. I tried _INetGetSource, but it is not foolproof. Edited August 10, 2009 by VinodKP
GEOSoft Posted August 10, 2009 Posted August 10, 2009 (edited) Hi, Thanks for the quick reply. But using _IECreate function is slower as compared to InetGet, I am looking for an alternative wherein I don't have to use Internet Explorer. I tried _INetGetSource, but it is not foolproof. Any code is only foolproof until a bigger fool comes along. There is nothing wrong with _InetGetSource(). This works for your problem ; #include<inet.au3> $sURL = "http://dundats.mvps.org/Windows/Win98/default.aspx" $aTables = StringRegExp(_InetGetSource($sURL), "(?i)(?s)(<table.+?</table>)", 3) If NOT @Error Then For $i = 0 To Ubound($aTables) -1 MsgBox(0, "Result", $aTables[$i], 2) Next EndIf ; EDIT: IF YOU ARE USING THE BETA then this will also work. ; $sURL = "http://dundats.mvps.org/Windows/Win98/default.aspx" $sTemp = @TempDir & "\test.htm" If FileExists($sTemp) Then FileDelete($sTemp) Local $hDownload = InetGet($sURL, $sTemp, 1, 1) Do Sleep(250) Until InetGetInfo($hDownload, 2) ; Check if the download is complete. InetClose($hDownload) ; Close the handle to release resources. $sStr = FileRead($sTemp) FileDelete($sTemp) $aTables = StringRegExp($sStr, "(?i)(?s)(<table.+?</table>)", 3) If NOT @Error Then For $i = 0 To Ubound($aTables) -1 MsgBox(0, "Result", $aTables[$i], 2) Next EndIf ; Edited August 10, 2009 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!"
VinodKP Posted August 11, 2009 Author Posted August 11, 2009 Hi George, Thanks for the information. I am looking for something which gives me the result similar to the one below. _IETableGetCollection was perfect for this, but it is slow and is eating lot's of system resource. I will be looping this code for various symbol values and then feed it to a GUI. #include <Array.au3> #include <IE.au3> $Symbol = "TCS" $Key = $Symbol & "EQN" $flag = 0 $URL = "http://www.nseindia.com/marketinfo/equities/cmquote_printer.jsp?key=" & $Key & "&symbol=" & $Symbol & "&flag=" & $flag $oIE = _IECreate("", 0, 0, 1, 1) While 1 _IENavigate($oIE,$URL,1) $oTable = _IETableGetCollection ($oIE) $iNumTables = @extended $oTable = _IETableGetCollection ($oIE, 4) ;~ 4 for Price details, $aTableData = _IETableWriteToArray ($oTable, True) ;~ _ArrayDisplay($aTableData, 4) TrayTip ("",$aTableData[4][0] & " is " & $aTableData[4][1],7) Sleep (7000) WEnd _IEQuit($oIE)
GEOSoft Posted August 11, 2009 Posted August 11, 2009 (edited) I know this can be shortened but my head's just not into it right now. This will get you started for now and I'll re-visit it later. Or you can play with it. It seems that the best method is to use the second parameter in the _GetTables() call. Here I've used the table you used in your screenshot(Price Information). Nothing is case sensitive expandcollapse popup; #include<array.au3> ;; For displaying the arrays only $Symbol = "TCS" $Key = $Symbol & "EQN" $flag = 0 $sURL = "http://www.nseindia.com/marketinfo/equities/cmquote_printer.jsp?key=" & $Key & "&symbol=" & $Symbol & "&flag=" & $flag $sTemp = @TempDir & "\test.htm" If FileExists($sTemp) Then FileDelete($sTemp) Local $hDownload = InetGet($sURL, $sTemp, 1, 1) Do Sleep(250) Until InetGetInfo($hDownload, 2) ; Check if the download is complete. InetClose($hDownload) ; Close the handle to release resources. _GetTables($sTemp, "Price information");; Leave the 2nd Parameter blank to display all the tables Func _GetTables($sPage, $sTable = -1) Local $sStr = FileRead($sPage), $sRegExp = "(?i)(?s)(<table.+?</table>)", $iRtn = 3 FileDelete($sPage) If $sTable <> -1 Then ;; a particular table was specified $sTable = StringRegExpReplace($sTable,"\s+", "\\s*") $sRegExp = "(?i)(?s).*(<table.+?" & $sTable & ".+?</table>)" $iRtn = 1 EndIf $aTables = StringRegExp($sStr, $sRegExp, $iRtn) If NOT @Error Then For $i = 0 To Ubound($aTables) -1 $aTables[$i] = StringRegExpReplace($aTables[$i], "(?i)(</?t)h.*?>", "$1d>") StringRegExpReplace($aTables[$i], "</tr>", "$1") $iRows = @Extended $iCols = _ColCount($aTables[$i]) Local $aData[$iRows][$iCols] _ColData($aTables[$i], $aData) _ArrayDisplay($aData, $iRows & " x " & $iCols) ;; If $sTable <> -1 then you can replace the _ArrayDisplay() with Return $aData Next EndIf EndFunc ;<==> _GetTables() Func _ColData($sTable, ByRef $aArray) Local $aRows = StringRegExp($sTable, "(?i)(?s)(<tr.+?</tr>)", 3), $aVlues If @Error Then Return SetError(1,1) For $i = 0 To Ubound($aRows) -1 $aValues = StringRegExp($aRows[$i],"(?i)(?s)<td.+?</td>", 3) If NOT @Error Then For $j = 0 To Ubound($aValues) -1 $aArray[$i][$j] = _StripTags($aValues[$j]) Next EndIf Next Return $aArray EndFunc ;<==> _ColData() Func _StripTags($sStr) $sStr = StringRegExpReplace($sStr, "(?i)(?s)<.+?>", "") $sStr = StringReplace($sStr, " ", "") Return StringStripWS($sStr,3) EndFunc ;<==> _StripTags() Func _ColCount($sTable) Local $iCount = 0, $iCols Local $aRows = StringRegExp($sTable, "(?i)(?s)(<tr.+?</tr>)", 3) If @Error Then Return SetError(1,1) For $i = 0 To Ubound($aRows) -1 StringRegExpReplace($aRows[$i], "(?i)(?s)(<td.+?</td>)", "$1") $iCols = @Extended If $iCols > $iCount Then $iCount = $iCols ;MsgBox(0, "Test Row", $aRows[$i], 2) Next Return $iCount EndFunc ;<==> _ColCount() ; Edited August 11, 2009 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!"
VinodKP Posted August 12, 2009 Author Posted August 12, 2009 Hi George, Thanks a lot for your help. The code works just perfect. Thank you very much. If anyone thinks they can do better than this, please let me know >_<. Here's the code which I have modified from your's to suite my requirement. expandcollapse popup#include<array.au3> ;; For displaying the arrays only #include <INet.au3> $Symbol = "TCS" $Key = $Symbol & "EQN" $flag = 0 $sURL = "http://www.nseindia.com/marketinfo/equities/cmquote_printer.jsp?key=" & $Key & "&symbol=" & $Symbol & "&flag=" & $flag $sData = _INetGetSource ($sURL) _GetTables($sData, "Price information");; Leave the 2nd Parameter blank to display all the tables Func _GetTables($sSource, $sTable = -1) ;; Leave the 2nd Parameter blank to display all the tables Local $sRegExp = "(?i)(?s)(<table.+?</table>)", $iRtn = 3 If $sTable <> -1 Then ;; a particular table was specified $sTitle = $sTable $sTable = StringRegExpReplace($sTable,"\s+", "\\s*") $sRegExp = "(?i)(?s).*(<table.+?" & $sTable & ".+?</table>)" $iRtn = 1 EndIf $aTables = StringRegExp($sSource, $sRegExp, $iRtn) If NOT @Error Then For $i = 0 To Ubound($aTables) -1 $aTables[$i] = StringRegExpReplace($aTables[$i], "(?i)(</?t)h.*?>", "$1d>") StringRegExpReplace($aTables[$i], "</tr>", "$1") $iRows = @Extended $iCols = _ColCount($aTables[$i]) Local $aData[$iRows][$iCols] _ColData($aTables[$i], $aData) _ArrayDisplay($aData, $iRows & " x " & $iCols & " x " & $sTitle) ;; If $sTable <> -1 then you can replace the _ArrayDisplay() with Return $aData Next EndIf EndFunc ;<==> _GetTables() Func _ColData($sTable, ByRef $aArray) Local $aRows = StringRegExp($sTable, "(?i)(?s)(<tr.+?</tr>)", 3), $aVlues If @Error Then Return SetError(1,1) For $i = 0 To Ubound($aRows) -1 $aValues = StringRegExp($aRows[$i],"(?i)(?s)<td.+?</td>", 3) If NOT @Error Then For $j = 0 To Ubound($aValues) -1 $aArray[$i][$j] = _StripTags($aValues[$j]) Next EndIf Next Return $aArray EndFunc ;<==> _ColData() Func _StripTags($sStr) $sStr = StringRegExpReplace($sStr, "(?i)(?s)<.+?>", "") $sStr = StringReplace($sStr, " ", "") Return StringStripWS($sStr,3) EndFunc ;<==> _StripTags() Func _ColCount($sTable) Local $iCount = 0, $iCols Local $aRows = StringRegExp($sTable, "(?i)(?s)(<tr.+?</tr>)", 3) If @Error Then Return SetError(1,1) For $i = 0 To Ubound($aRows) -1 StringRegExpReplace($aRows[$i], "(?i)(?s)(<td.+?</td>)", "$1") $iCols = @Extended If $iCols > $iCount Then $iCount = $iCols ;MsgBox(0, "Test Row", $aRows[$i], 2) Next Return $iCount EndFunc ;<==> _ColCount() ; The only difference from your's is I used _INetGetSource, so that I don't create any temp file in the system. Now it get's the data twice the speed of _IETableGetCollection and the load is much lower on my machine. Again thanks for your help
GEOSoft Posted August 12, 2009 Posted August 12, 2009 I normally use _InetGetSource() myself. Not sure why I didn't this time except that I was already working with InetGet() on something else I was doing. When the next Beta is released InetRead() is supposed to be fixed and I have a hunch it will be faster yet. 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!"
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