【已解决】求各位前辈赐教关于_HtmlTableGetWriteToArray函数
本帖最后由 laoxgogo 于 2022-6-30 17:29 编辑Func _WD_GetTable($sSession, $sBaseElement)
Local Const $sFuncName = “_WD_GetTable”
Local $aElements, $sElement, $iLines, $iRow, $iColumns, $iColumn, $sHTML
$_WD_HTTPRESULT = 0
$_WD_HTTPRESPONSE = ''
;确定可选 UDF 是否可用
Call(“_HtmlTableGetWriteToArray”, “”)
如果 @error = 0xDEAD 并且 @extended = 0xBEEF 则
$aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sBaseElement & “/tbody/tr”, “”, True) ;检索表行
数 如果 @error <> $_WD_ERROR_Success 则返回 SetError(__WD_Error($sFuncName, @error), 0, “”)
$iLines = UBound($aElements)
$aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sBaseElement & “/tbody/tr/td”, “”, True) ;通过检查第一个表行
来检索表列数 如果 @error <> $_WD_ERROR_Success 则返回 SetError(__WD_Error($sFuncName, @error), 0, “”)
$iColumns = UBound($aElements)
Local $aTable[$iLines][$iColumns] ;创建 AutoIt 数组以保存表
的所有单元格 $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sBaseElement & “/tbody/tr/td”, “”, True) ;检索所有表单元格
如果 @error <> $_WD_ERROR_Success 则返回 SetError(__WD_Error($sFuncName, @error), 0, “”)
for $i = 0 To UBound($aElements) - 1
$iRow = Int($i / $iColumns) ;计算 AutoIt 数组中存储单元格值
的行/列 $iColumn = Mod($i, $iColumns)
$aTable[$iRow][$iColumn] = _WD_ElementAction($sSession, $aElements[$i], “Text”) ;检索每个表单元格
的文本 如果 @error <> $_WD_ERROR_Success 则返回 SetError(__WD_Error($sFuncName, @error), 0, “”)
下一页
Else
;获取 table 元素
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sBaseElement)
如果 @error <> $_WD_ERROR_Success 则返回 SetError(__WD_Error($sFuncName, @error), 0, “”)
;检索其 HTML
$sHTML = _WD_ElementAction($sSession, $sElement, “Property”, “outerHTML”)
如果 @error <> $_WD_ERROR_Success 则返回 SetError(__WD_Error($sFuncName, @error), 0, “”)
;Convert to array
$aTable = _HtmlTableGetWriteToArray($sHTML, 1, False, $_WD_IFILTER)
EndIf
Return $aTable
EndFunc ;==>_WD_GetTable
关于WebDriver-0.9.1 wd_helper.au3 中的_HtmlTableGetWriteToArray函数哪来的?论坛查不到,求各位前辈赐教!感激不尽!!! 之前想查查_WD_GetTable这个函数怎么用,然后老是读不出来,去官网论坛看看发现了下面的那个函数,能读但是很慢,都还不如ie的_IETableWriteToArray
Func _WD_GetTable_2($sSession, $sTableXpath)
;~ Const $sFuncName = "_WD_GetTable_2"
Local $aTable, $aRowElements, $aColElements
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[$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 https://www.autoitscript.com/forum/topic/167679-read-data-from-html-tables-from-raw-html-source/ redapple2008 发表于 2022-6-27 14:53
https://www.autoitscript.com/forum/topic/167679-read-data-from-html-tables-from-raw-html-source/
谢谢前辈指点!!!:face (10):
页:
[1]