|
楼主 |
发表于 2022-6-27 14:43:46
|
显示全部楼层
之前想查查_WD_GetTable这个函数怎么用,然后老是读不出来,去官网论坛看看发现了下面的那个函数,能读但是很慢,都还不如ie的_IETableWriteToArray
Func _WD_GetTable_2($sSession, $sTableXpath)
;~ Const $sFuncName = "_WD_GetTable_2"
Local $aTable[0], $aRowElements[0], $aColElements[0]
Local $sRowColumns = ""
Local $iRows = 0, $iCols = 0, $iChildCount = 0
;Get table row elements
$aRowElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sTableXpath & "/tbody/tr", "", True)
If @error <> $_WD_ERROR_Success Then Return "cw"
$iRows = UBound($aRowElements)
;Find max number of columns by checking each row's child count property
For $iRow = 0 To UBound($aRowElements) - 1
$iChildCount = _WD_ElementAction($sSession, $aRowElements[$iRow], "property", "childElementCount")
If @error <> $_WD_ERROR_Success Then Return "cw"
;If number of row columns is greater the previous value, then save new value
If $iChildCount > $iCols Then $iCols = $iChildCount
Next
;Dimension and load table data
ReDim $aTable[0][$iCols]
For $iRow = 0 To $iRows - 1
;Get column elements (td or th)
$aColElements = _WD_FindElement($sSession, _
$_WD_LOCATOR_ByXPath, _
"./td|./th", _
$aRowElements[$iRow], _
True)
If @error <> $_WD_ERROR_Success Then Return "cw"
;Build pipe-separated row of column data
$sRowColumns = ""
For $iCol = 0 To UBound($aColElements) - 1
If $iCol = 0 Then
$sRowColumns &= _WD_ElementAction($sSession, $aColElements[$iCol], "text")
Else
$sRowColumns &= "|" & _WD_ElementAction($sSession, $aColElements[$iCol], "text")
EndIf
Next
;Add row to array
_ArrayAdd($aTable, $sRowColumns)
Next
;Return result table
Return $aTable
EndFunc |
|