Что нового

Выбор данных из вложенных таблиц в массив

Vitorio

Новичок
Сообщения
18
Репутация
0
Есть некая таблица:
<div id="reztab" class="x1mn" style="position: relative; width: 1589px; overflow: hidden; height: 174px; z-index: 1;" _afrcolcount="23">
<table class="gy7jl" style="table-layout: fixed; position: relative; width: 1589px;" _frwidth="330" _totalwidth="2310" _selstate="{'51':true}" _rowcount="3" _startrow="0" cellspacing="0">
<tbody>
<tr class="xha " _afrrk="51">
<td class="x1n7" style="width:35px;text-align:center;" _afrrh="true" nowrap="">1</td>
<td class="xhb" style="width:40px;" nowrap="" align="center">20</td>
<td class="xhb" style="width:40px;" nowrap="" align="center">26</td>
<td class="xhb" style="width:50px;" nowrap="" align="center">Б</td>
<td class="xhb x1ne" style="width:140px;" nowrap="" align="center">11111111</td>
<td style="padding: 0px; width: 1259px;">
<div style="position:relative;overflow:hidden;width:100%">
<table summary="" style="table-layout:fixed;width:1980px" _afrit="1" cellspacing="0">
<tbody>
<tr>
<td class="xhb" style="width:50px;" nowrap="" align="center">25</td>
<td class="xhb" style="width:80px;" nowrap="" align="center">-</td>
<td class="xhb" style="width:40px;" nowrap="" align="center">
<span style="cursor: text;">85</span>
</td>
<td class="xhb" style="width:80px;" nowrap="" align="center">500</td>
<td class="xhb" style="width:40px;" nowrap="" align="center">57</td>
<td class="xhb" style="width:40px;" nowrap="" align="center">06</td>
<td class="xhb" style="width:50px;" nowrap="" align="center">299</td>
<td class="xhb" style="width:100px;" nowrap="" align="center">1055</td>
<td class="xhb" style="width:100px;" nowrap="" align="center">60570</td>
<td class="xhb" style="width:200px;text-align:left;" nowrap="" align="center">Автомобиль</td>
<td class="xhb" style="width:50px;" nowrap="" align="center">821018</td>
<td class="xhb" style="width:100px;" nowrap="" align="center">
<span style="cursor: text;">700357</span>
</td>
<td class="xhb" style="width:200px;text-align:left;" nowrap="" align="center">
<span style="cursor: text;">10500</span>
</td>
<td class="xhb" style="width:80px;text-align:right;" nowrap="" align="center">2000</td>
<td class="xhb" style="width:158px;" nowrap="" align="left">ЛРПА675ПН</td>
<td class="xhb" style="width:22px;" nowrap="" align="center">28.07.2017</td>
<td class="xhb" style="width:400px;color:red;" nowrap="" align="center">Станислав</td>
<td class="xhb" style="width:100px;" nowrap="">9886</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
<tr class="xha" _afrrk="52">
<td class="x1n7" style="text-align:center;" _afrrh="true" nowrap="">2</td>
<td class="xhb" nowrap="" align="center">20</td>
<td class="xhb" nowrap="" align="center">26</td>
<td class="xhb" nowrap="" align="center">Б</td>
<td class="xhb x1ne" nowrap="" align="center">11111111</td>
<td style="padding:0px">
<div style="position:relative;overflow:hidden;width:100%">
<table summary="" style="table-layout:fixed;width:1980px" _afrit="1" cellspacing="0">
<tbody>
<tr>
<td class="xhb" style="width:50px;" nowrap="" align="center">25</td>
<td class="xhb" style="width:80px;" nowrap="" align="center">-</td>
<td class="xhb" style="width:40px;" nowrap="" align="center">
<span style="cursor: text;">85</span>
</td>
<td class="xhb" style="width:80px;" nowrap="" align="center">500</td>
<td class="xhb" style="width:40px;" nowrap="" align="center">57</td>
<td class="xhb" style="width:40px;" nowrap="" align="center">06</td>
<td class="xhb" style="width:50px;" nowrap="" align="center">299</td>
<td class="xhb" style="width:100px;" nowrap="" align="center">1055</td>
<td class="xhb" style="width:100px;" nowrap="" align="center">60570</td>
<td class="xhb" style="width:200px;text-align:left;" nowrap="" align="center">Тягач</td>
<td class="xhb" style="width:50px;" nowrap="" align="center">821018</td>
<td class="xhb" style="width:100px;" nowrap="" align="center">
<span style="cursor: text;">700357</span>
</td>
<td class="xhb" style="width:200px;text-align:left;" nowrap="" align="center">
<span style="cursor: text;">Владивосток</span>
</td>
<td class="xhb" style="width:80px;text-align:right;" nowrap="" align="center">6985</td>
<td class="xhb" style="width:158px;" nowrap="" align="left">ДШВАР89ПАВ</td>
<td class="xhb" style="width:22px;" nowrap="" align="center">28.07.2017</td>
<td class="xhb" style="width:400px;color:red;" nowrap="" align="center">Виктор</td>
<td class="xhb" style="width:100px;" nowrap="">4563</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
<tr class="p_AFSelected p_AFFocused xha" _afrrk="53">
<td class="x1n7" style="text-align:center;" _afrrh="true" nowrap="">3</td>
<td class="xhb" nowrap="" align="center">20</td>
<td class="xhb" nowrap="" align="center">26</td>
<td class="xhb" nowrap="" align="center">Б</td>
<td class="xhb x1ne" nowrap="" align="center">11111111</td>
<td style="padding:0px">
<div style="position:relative;overflow:hidden;width:100%">
<table summary="" style="table-layout:fixed;width:1980px" _afrit="1" cellspacing="0">
<tbody>
<tr>
<td class="xhb" style="width:50px;" nowrap="" align="center">25</td>
<td class="xhb" style="width:80px;" nowrap="" align="center">-</td>
<td class="xhb" style="width:40px;" nowrap="" align="center">85</td>
<td class="xhb" style="width:80px;" nowrap="" align="center">
<span style="cursor: text;">500</span>
</td>
<td class="xhb" style="width:40px;" nowrap="" align="center">57</td>
<td class="xhb" style="width:40px;" nowrap="" align="center">06</td>
<td class="xhb" style="width:50px;" nowrap="" align="center">299</td>
<td class="xhb" style="width:100px;" nowrap="" align="center">1055</td>
<td class="xhb" style="width:100px;" nowrap="" align="center">60570</td>
<td class="xhb" style="width:200px;text-align:left;" nowrap="" align="center">Трактор</td>
<td class="xhb" style="width:50px;" nowrap="" align="center">821018</td>
<td class="xhb" style="width:100px;" nowrap="" align="center">700357</td>
<td class="xhb" style="width:200px;text-align:left;" nowrap="" align="center">
<span style="cursor: text;">Бобруйск</span>
</td>
<td class="xhb" style="width:80px;text-align:right;" nowrap="" align="center">6734</td>
<td class="xhb" style="width:158px;" nowrap="" align="left">H0728TIAQE</td>
<td class="xhb" style="width:22px;" nowrap="" align="center">28.07.2017</td>
<td class="xhb" style="width:400px;color:red;" nowrap="" align="center">Дмитрий</td>
<td class="xhb" style="width:100px;" nowrap="">675789</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
</div>
которая содержит вложенные таблицы (каждая в своём <div>).
Задача - выбрать данные из этих вложенных таблиц в массив для последующей обработки. Не могу ни к чему привязаться. :( У этих див-ов, как и у таблиц нет никаких атрибутов, за которые можно было бы зацепиться. Подскажите, пожалуйста, возможные варианты решения.
 

Garrett

Модератор
Локальный модератор
Сообщения
3,999
Репутация
967
Vitorio [?]
Не могу ни к чему привязаться
Код:
#include<Array.au3>
#include<IE.au3>

$oIE = _IECreate("http://...")
$oEl = _IEGetObjById($oIE, "reztab")
$oTable = $oEl.firstElementChild
$oTBody = $oTable.firstElementChild
$oTR = $oTBody.Children
$iRLen = $oTR.length
Local $aData[$iRLen]

For $i = 0 To $iRLen -1
   $oTable = $oTR($i).lastElementChild.lastElementChild.lastElementChild
   $aData[$i] = _TableToArray($oTable)[0]
Next

_ArrayDisplay($aData[0], ($aData[0])[9])
_ArrayDisplay($aData[1], ($aData[1])[9])
_ArrayDisplay($aData[2], ($aData[2])[9])


_IEQuit($oIE)


Func _TableToArray($oElement)

   Local $oRows = $oElement.querySelectorAll('tr')
   Local $iRLen = $oRows.length
   Local $aData[$iRLen], $sData = ""

   For $i = 0 To $iRLen -1
	  Local $oCells = $oRows.item($i).querySelectorAll('td')
	  Local $iCLen = $oCells.length
	  For $j = 0 To $iCLen -1
		 Local $oCell = $oCells.item($j)
		 $sData &= $oCell.innerText &"%"
	  Next
	  $aData[$i] = StringSplit(StringTrimRight($sData, 1), "%", 2)
   Next

   Return $aData
EndFunc ;==>_TableToArray
 
Верх