我试图在firefox控制台上获取所有表数据。我可以获取一些span ID。但是我无法访问表。我试图在下面编写代码。
我尝试使用此代码来访问表。
var x = document.getElementById("table-positions").rows[0].cells.length;
但是它返回undefined
示例:
var x = document.getElementById("table-positions").rows[0].cells.length;
console.log(x);
<table id="table-positions" class="grid tablesorter">
<thead>
<tr>
<th class="provider header sorting_desc" style="display: table-cell;">Trader</th>
<th class="header">Currency</th>
<th class="header">Type</th>
<th class="header-lots header">Mini Lots</th>
<th class="header">Date opened</th>
<th class="header">Entry</th>
<th class="header">Stop</th>
<th class="header">Limit</th>
<th class="header">Current</th>
<th class="header">Profit</th>
<th class="last-cell-open-trades"> </th>
</tr>
</thead>
<tbody id="table-body-positions"><tr class="trade p-364967">
<td class="provider bold" style="display: table-cell;"><a href="/trader/364967" target="_blank">WaveDrive</a></td>
<td>EUR/USD</td>
<td class="c-1">BUY</td>
<td>1.6</td>
<td><a data-action="details"><span><span class="">2019/01/04 13:36:19</span></span></a></td>
<td>1.13755</td>
<td><a data-action="update-stop" data-filter="stop" class="">1.08809 (-494.6)<br>-$791.36</a></td>
<td><a data-action="update-limit" data-filter="limit">1.18809 (505.4)<br>$808.64</a></td>
<td>1.13601</td>
<td class="c-1">-15.4 pips<br>-$27.04</td>
<td class="actions">
<a data-action="update-lock" class=""><span><svg class="icon-svg icon-locker-open"><use xlink:href="/Static/Images/Sprites/symbol-defs.svg?b21b2663b89c00de708b9c02ef50197996#icon-locker-open"></use></svg></span></a>
<a data-action="close-trade" class=""><span><svg class="icon-svg icon-x"><use xlink:href="/Static/Images/Sprites/symbol-defs.svg?b21b2663b89c00de708b9c02ef50197996#icon-x"></use></svg></span></a>
</td>
</tr><tr class="trade p-364967">
<td class="provider bold" style="display: table-cell;"><a href="/trader/364967" target="_blank">WaveDrive</a></td>
<td>EUR/USD</td>
<td class="c-2">BUY</td>
<td>1.6</td>
<td><a data-action="details"><span><span class="">2019/01/04 13:35:17</span></span></a></td>
<td>1.13868</td>
<td><a data-action="update-stop" data-filter="stop" class="">1.08865 (-500.3)<br>-$800.48</a></td>
<td><a data-action="update-limit" data-filter="limit">1.18865 (499.7)<br>$799.52</a></td>
<td>1.13601</td>
<td class="c-2">-26.7 pips<br>-$45.12</td>
<td class="actions">
<a data-action="update-lock" title="Lock or unlock this trade: A locked trade will prevent the trader or Automator from sending signals for this trade. As a result this trade will only be closed if the set Stop/Limit is reached or if you close it manually!"><span><svg class="icon-svg icon-locker-open"><use xlink:href="/Static/Images/Sprites/symbol-defs.svg?b21b2663b89c00de708b9c02ef50197996#icon-locker-open"></use></svg></span></a>
<a data-action="close-trade" title="Close"><span><svg class="icon-svg icon-x"><use xlink:href="/Static/Images/Sprites/symbol-defs.svg?b21b2663b89c00de708b9c02ef50197996#icon-x"></use></svg></span></a>
</td>
</tr><tr class="trade p-364967">
<td class="provider bold" style="display: table-cell;"><a href="/trader/364967" target="_blank">WaveDrive</a></td>
<td>EUR/USD</td>
<td class="c-1">BUY</td>
<td>1.6</td>
<td><a data-action="details"><span><span class="">2019/01/04 13:47:11</span></span></a></td>
<td>1.13715</td>
<td><a data-action="update-stop" data-filter="stop" class="">1.08709 (-500.6)<br>-$800.96</a></td>
<td><a data-action="update-limit" data-filter="limit">1.18709 (499.4)<br>$799.04</a></td>
<td>1.13601</td>
<td class="c-1">-11.4 pips<br>-$20.64</td>
<td class="actions">
<a data-action="update-lock" title="Lock or unlock this trade: A locked trade will prevent the trader or Automator from sending signals for this trade. As a result this trade will only be closed if the set Stop/Limit is reached or if you close it manually!"><span><svg class="icon-svg icon-locker-open"><use xlink:href="/Static/Images/Sprites/symbol-defs.svg?b21b2663b89c00de708b9c02ef50197996#icon-locker-open"></use></svg></span></a>
<a data-action="close-trade" title="Close"><span><svg class="icon-svg icon-x"><use xlink:href="/Static/Images/Sprites/symbol-defs.svg?b21b2663b89c00de708b9c02ef50197996#icon-x"></use></svg></span></a>
</td>
</tr><tr class="group-provider ui-helper-hidden" id="123">
<td colspan="8" class="group-provider-name">
<div class="group-collapse section__title section__title--grey section__title--open"></div>
<a class="" target="_blank" href="/trader/364967">
<img src="/image.ashx?type=provider&size=s&id=364967" alt="Manual"><strong>WaveDrive</strong>
</a>
<span class="manual ui-helper-hidden"><strong>Manual</strong></span>
<span class="group-provider-details"><strong>3</strong> Open Positions | <strong> 4.8 </strong> Mini Lots</span>
</td>
<td class="c-1">-16.3 pips<br>-$33.28</td>
<td>
<button data-action="close-all-by-provider" data-pending="false">Close All</button>
</td>
<td style="display: none"></td>
<td style="display: none"></td>
<td style="display: none"></td>
<td style="display: none"></td>
<td style="display: none"></td>
<td style="display: none"></td>
<td style="display: none"></td>
</tr></tbody>
</table>
“表汇总位置”表的结果也相同。
下面是图片的样子。
此表是动态的,可能增加或减少了行。如何获取所有数据?