#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=IE_Common.au3.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include-once #include Const $IE = "[REGEXPTITLE:.*- Internet Explorer]"; ; Error handeling Global $AtError Global $AtExtended _IEErrorNotify(True) ;Global $oErrorHandler = ObjEvent("AutoIt.Error", "MyErrFunc") _IEErrorHandlerRegister("MyErrFunc") $__g_bIEAU3Debug = False $__g_bIEErrorNotify = False ; Sometimes there is large amount of data to display... Global $DumpAllTags = False Global $TruncateDump = True Global $TruncateAfter = 34 ; Truncate long lines after this amount Func TruncateLong($sMsg) Local $iLen = StringLen($sMsg) If ($iLen > $TruncateAfter) Then If ($TruncateDump) Then Return $iLen & " = <" & StringLeft($sMsg, $TruncateAfter) & "... >" EndIf EndIf Return $iLen & " = <" & $sMsg & "> " EndFunc ;==>TruncateLong ;++++++++++++++++++++++++++++++++++ ; https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML ;++++++++++++++++++++++++++++++++++ Func listAttributes(ByRef $oObject) ;Arguments: ; $sObject [object] Referenct to the object to be return when found Local $Func = "listAttributes"; Local $iCount = 0 Local $item ;If $oObject.hasAttributes() Then Local $attrs = $oObject.attributes $iCount = $attrs.length For $i = 0 To $iCount - 1 $item = $attrs.item($i) If ($item.value <> "") Then ConsoleWrite(@TAB & @TAB & $item.name & "->" & $item.value & @CRLF); EndIf Next ;EndIf EndFunc ;==>listAttributes Func PageInfo(ByRef $oIE) Local $Txt Local $iIdx Local $iIdx2 ConsoleWrite( "PageInfo" & @CRLF) ;---------------------- Local $oForms = _IEFormGetCollection($oIE) If ($AtError = 0) Then Local $iNumForms = $AtExtended ConsoleWrite( "Forms Info: There are " & $iNumForms & " forms on this page" & @CRLF) $iIdx2 = 0 For $oForm In $oForms $iIdx2 = $iIdx2 + 1 ConsoleWrite( @TAB & "Form " & $iIdx2 & " Info: .name = " & $oForm.name & @CRLF) Local $oElements = _IEFormElementGetCollection($oForm) Local $iNumFormElements = @extended ConsoleWrite( @TAB & "Elements Info: There are " & $iNumFormElements & " elements in this form" & @CRLF) $iIdx = 0 For $oElement In $oElements $Txt = "Index:" & $iIdx $iIdx = $iIdx + 1 With $oElement If .name Then $Txt &= " .name:" & .name EndIf If .id Then $Txt &= " .id:" & .id EndIf EndWith ConsoleWrite( @TAB & @TAB & $Txt & @CRLF) Next Next EndIf ;---------------------- Local $oFrames = _IEFrameGetCollection($oIE) If ($AtError = 0) Then Local $iNumFrames = $AtExtended ConsoleWrite( "Frames Info: There are " & $iNumFrames & " frames on this page" & @CRLF) Local $oFrame = 0 $iIdx = 0 For $i = 0 To ($iNumFrames - 1) $Txt = @TAB & @TAB & "Frame Info:" & $iIdx $iIdx = $iIdx + 1 $oFrame = _IEFrameGetCollection($oIE, $i) If ($AtError = 0) Then With $oFrame If .name Then $Txt &= " .Name:" & .name EndIf ;If .id Then ; $Txt &= " .id:" & .id ;EndIf Local $oText = _IEPropertyGet($oFrame, "innertext") If $oText Then $Txt &= " .innertext:" & TruncateLong($oText) EndIf EndWith EndIf ConsoleWrite( $Txt & @CRLF) Next EndIf ;---------------------- ; http://www.w3schools.com/TAGS/default.asp ; If ($DumpAllTags) Then Local $oTagNames = _IETagNameAllGetCollection($oIE) If ($AtError = 0) Then Local $iNumTagNames = $AtExtended ConsoleWrite( "TagName Info: There are " & $iNumTagNames & " TagName on this page" & @CRLF) $iIdx = 0 For $oTagName In $oTagNames ConsoleWrite( @TAB & "TagName Index:" & $iIdx & " Name:" & $oTagName.tagname & @CRLF) listAttributes($oTagName) $iIdx = $iIdx + 1 Next EndIf EndIf ;---------------------- ; http://www.w3schools.com/tags/tag_input.asp Local $oInputs = _IETagNameGetCollection($oIE, "input") If ($AtError = 0) Then Local $iNumInputs = $AtExtended ConsoleWrite( "Input Info: There are " & $iNumInputs & " inputs on this page" & @CRLF) $iIdx = 0 For $oInput In $oInputs $Txt = @TAB & "Input " & $iIdx $iIdx = $iIdx + 1 With $oInput If .form.name Then $Txt &= " .form.name:" & .form.name EndIf If .tagname Then $Txt &= " .tagname:" & .tagname EndIf If .name Then $Txt &= " .name:" & .name EndIf If .id Then $Txt &= " .id:" & .id EndIf If .type Then $Txt &= " .type:" & .type EndIf EndWith ConsoleWrite( $Txt & @CRLF) Next EndIf ;---------------------- ; http://www.w3schools.com/tags/tag_a.asp Local $oHyperLinks = _IETagNameGetCollection($oIE, "a") If ($AtError = 0) Then Local $iNumHyperLinks = $AtExtended ConsoleWrite( "HyperLink Info: There are " & $iNumHyperLinks & " HyperLinks on this page" & @CRLF) $iIdx = 0 For $oHyperLink In $oHyperLinks $Txt = @TAB & "HyperLink " & $iIdx $iIdx = $iIdx + 1 With $oHyperLink If .tagname Then $Txt &= " .tagname:" & .tagname EndIf If .name Then $Txt &= " .name:" & .name EndIf If .id Then $Txt &= " .id:" & .id EndIf If .type Then $Txt &= " .type:" & .type EndIf If .rel Then $Txt &= " .rel:" & .rel EndIf If .innertext Then $Txt &= " .innertext:" & TruncateLong(.innertext) EndIf EndWith ConsoleWrite( $Txt & @CRLF) Next EndIf ;---------------------- ; http://www.w3schools.com/tags/tag_button.asp Local $oButtons = _IETagNameGetCollection($oIE, "button") If ($AtError = 0) Then Local $iNumButtons = $AtExtended ConsoleWrite( "Buttons: There are " & $iNumInputs & " Button on this page" & @CRLF) $iIdx = 0 For $oButton In $oButtons $Txt = @TAB & "Button " & $iIdx $iIdx = $iIdx + 1 With $oButton If .name Then $Txt &= " .name:" & .name EndIf If .id Then $Txt &= " .id:" & .id EndIf If .type Then $Txt &= " .type:" & .type EndIf If .value Then $Txt &= " .value:" & .value EndIf EndWith ConsoleWrite( $Txt & @CRLF) Next EndIf ;---------------------- ; http://www.w3schools.com/tags/tag_div.asp Local $oDivs = _IETagNameGetCollection($oIE, "div") If ($AtError = 0) Then Local $iNumDivs = $AtExtended ConsoleWrite( "Divs: There are " & $iNumDivs & " divs on this page" & @CRLF) $iIdx = 0 For $oDiv In $oDivs $Txt = @TAB & "Div " & $iIdx $iIdx = $iIdx + 1 With $oDiv If .classname Then $Txt &= " .classname:" & .classname EndIf If .id Then $Txt &= " .id:" & .id EndIf If .title Then $Txt &= " .title:" & .title EndIf If .innertext Then $Txt &= " .innertext:" & TruncateLong(.innertext) EndIf EndWith ConsoleWrite( $Txt & @CRLF) Next EndIf ;---------------------- Local $oListItems = _IETagNameGetCollection($oIE, "li") If ($AtError = 0) Then Local $iNumListItems = $AtExtended ConsoleWrite( "ListsItem: There are " & $iNumListItems & " listsItems on this page" & @CRLF) $iIdx = 0 For $oListItem In $oListItems $Txt = @TAB & "ListItem " & $iIdx $iIdx = $iIdx + 1 With $oListItem If .classname Then $Txt &= " .classname:" & .classname EndIf If .id Then $Txt &= " .id:" & .id EndIf If .title Then $Txt &= " .title:" & .title EndIf If .type Then $Txt &= " .type:" & .type EndIf If .value Then $Txt &= " .value:" & .value EndIf If .innertext Then $Txt &= " .innertext:" & TruncateLong(.innertext) EndIf EndWith ConsoleWrite( $Txt & @CRLF) Next EndIf ;---------------------- ; http://www.w3schools.com/tags/tag_label.asp Local $oLabels = _IETagNameGetCollection($oIE, "label") If ($AtError = 0) Then Local $iNumLabels = $AtExtended ConsoleWrite( "Label Info: There are " & $iNumLabels & " Labels on this page" & @CRLF) $iIdx = 0 For $oLabel In $oLabels $Txt = @TAB & "Label " & $iIdx $iIdx = $iIdx + 1 With $oLabel If .tagname Then $Txt &= " .tagname:" & .tagname EndIf If .classname Then $Txt &= " .classname:" & .classname EndIf ; If .name Then ; $Txt &= " .name:" & .name ; EndIf If .innertext Then $Txt &= " .innertext:" & TruncateLong(.innertext) EndIf EndWith ConsoleWrite( $Txt & @CRLF) Next EndIf ;---------------------- ; http://www.w3schools.com/tags/tag_text.asp Local $oTexts = _IETagNameGetCollection($oIE, "text") If ($AtError = 0) Then Local $iNumTexts = $AtExtended ConsoleWrite( "Text Info: There are " & $iNumTexts & " Texts on this page" & @CRLF) $iIdx = 0 For $oText In $oTexts $Txt = @TAB & "Text " & $iIdx $iIdx = $iIdx + 1 With $oText If .tagname Then $Txt &= " .tagname:" & .tagname EndIf If .classname Then $Txt &= " .classname:" & .classname EndIf If .id Then $Txt &= " .id:" & .id EndIf If .innertext Then $Txt &= " .innertext:" & TruncateLong(.innertext) EndIf EndWith ConsoleWrite( $Txt & @CRLF) Next EndIf ;---------------------- ; http://www.w3schools.com/tags/tag_img.asp Local $oImages = _IEImgGetCollection($oIE) If ($AtError = 0) Then Local $iNumImages = $AtExtended ConsoleWrite( "Images Info: There are " & $iNumImages & " images on this page" & @CRLF) $iIdx = 0 For $oImage In $oImages $Txt = @TAB & "Image Index " & $iIdx $iIdx = $iIdx + 1 With $oImage If .id Then $Txt &= " .id:" & .id EndIf If .alt Then $Txt &= " .alt:" & .alt EndIf If .height Then $Txt &= " .height:" & .height EndIf If .width Then $Txt &= " .width:" & .width EndIf If .src Then ;$Txt &= " .src:" & .src EndIf EndWith ConsoleWrite( $Txt & @CRLF) Next EndIf ;---------------------- ; http://www.w3schools.com/tags/tag_link.asp Local $oLinks = _IELinkGetCollection($oIE) If ($AtError = 0) Then Local $iNumLinks = $AtExtended ConsoleWrite( "Links Info: There are " & $iNumLinks & " links on this page" & @CRLF) $iIdx = 0 For $oLink In $oLinks $Txt = @TAB & "Link Index " & $iIdx $iIdx = $iIdx + 1 With $oLink If .href Then $Txt &= " .href:" & .href EndIf EndWith ConsoleWrite( $Txt & @CRLF) Next EndIf ;---------------------- Local $oTables = _IETableGetCollection($oIE) If ($AtError = 0) Then Local $iNumTables = $AtExtended Local $aTableData ConsoleWrite( "There are " & $iNumTables & " tables on the page" & @CRLF) $iIdx = 0 For $oTable In $oTables $Txt = @TAB & "Table Index " & $iIdx $iIdx = $iIdx + 1 $aTableData = _IETableWriteToArray($oTable) Local $iDims = UBound($aTableData, $UBOUND_DIMENSIONS) Local $iRows = UBound($aTableData, $UBOUND_ROWS) Local $iCols = UBound($aTableData, $UBOUND_COLUMNS) If $iDims > 2 Then ConsoleWrite( "Larger than 2D array passed to function" & @CRLF & @CRLF) Else ; Fill the array with data. $Txt &= " Dim:" & $iDims & " Row:" & $iRows & " Col:" & $iCols ConsoleWrite( $Txt & @CRLF) For $i = 0 To $iRows - 1 $Txt = @TAB & @TAB For $j = 0 To $iCols - 1 $Txt &= "[" & $i & ", " & $j & "]:" & TruncateLong($aTableData[$i][$j]) Next ConsoleWrite( $Txt & @CRLF) Next EndIf ConsoleWrite( $Txt & @CRLF) Next EndIf EndFunc ;==>PageInfo Func MyErrFunc() ; Register a customer error handler ;_IEErrorHandlerRegister("MyErrFunc") ; Do something ; Deregister the customer error handler ;_IEErrorHandlerDeRegister() ; Do something else ; Register the default IE.au3 COM Error Handler ;_IEErrorHandlerRegister() ; Do more work ; Important: the error object variable MUST be named $__g_oIEErrorHandler Local $ErrorNumber = $__g_oIEErrorHandler.number & " (0x" & Hex($__g_oIEErrorHandler.number, 8) & ")" Local $ErrorSource = $__g_oIEErrorHandler.Source Local $ErrorRetCode = "0x" & Hex($__g_oIEErrorHandler.retcode) Local $ErrorHelpFile = $__g_oIEErrorHandler.HelpFile Local $ErrorScriptline = $__g_oIEErrorHandler.scriptline Local $ErrorHelpContext = $__g_oIEErrorHandler.HelpContext Local $ErrorDescription = StringStripWS($__g_oIEErrorHandler.description, 2) Local $ErrorLastDllError = $__g_oIEErrorHandler.LastDllError Local $ErrorWinDescription = StringStripWS($__g_oIEErrorHandler.WinDescription, 2) Local $ErrorOutput = "" & @CRLF $ErrorOutput &= "--> COM Error Encountered in " & @ScriptName & @CRLF $ErrorOutput &= "----> Number = " & $ErrorNumber & @CRLF $ErrorOutput &= "----> Source = " & $ErrorSource & @CRLF $ErrorOutput &= "----> RetCode = " & $ErrorRetCode & @CRLF $ErrorOutput &= "----> HelpFile = " & $ErrorHelpFile & @CRLF $ErrorOutput &= "----> Scriptline = " & $ErrorScriptline & @CRLF $ErrorOutput &= "----> HelpContext = " & $ErrorHelpContext & @CRLF $ErrorOutput &= "----> Description = " & $ErrorDescription & @CRLF $ErrorOutput &= "----> LastDllError = " & $ErrorLastDllError & @CRLF $ErrorOutput &= "----> WinDescription = " & $ErrorWinDescription & @CRLF ;MsgBox(0, "COM Error", $ErrorOutput) ConsoleWrite( "IE_Comm_Error " & $ErrorOutput & @CRLF) ;SetError(1) Return EndFunc ;==>MyErrFunc Local $oIE_table = _IE_Example("table") PageInfo($oIE_table);