<table class="table table-striped">
<thead>
<tr class="reactable-column-header">
<th class="reactable-th-status reactable-header-sortable " role="button" tabindex="0"><strong></strong></th>
<th class="reactable-th-question_id reactable-header-sortable reactable-header-sort-asc" role="button"
tabindex="0"><strong>#</strong></th>
<th class="reactable-th-question_title reactable-header-sortable " role="button" tabindex="0">
<strong>Title</strong></th>
<th class="reactable-th-editorial reactable-header-sortable " role="button" tabindex="0">
<strong>Solution</strong></th>
<th class="reactable-th-acceptance reactable-header-sortable " role="button" tabindex="0">
<strong>Acceptance</strong></th>
<th class="reactable-th-difficulty reactable-header-sortable " role="button" tabindex="0">
<strong>Difficulty</strong></th>
<th class="reactable-th-frequency reactable-header-sortable " role="button" tabindex="0"><strong>Frequency
<span id="frequency-tooltip" class="fa fa-lock" data-toggle="tooltip" data-placement="top" title=""
data-original-title="Only premium members can see the frequency"></span></strong></th>
</tr>
</thead>
<tbody class="reactable-data">
<tr>
<td label="[object Object]"></td>
<td label="[object Object]">1</td>
<td value="Two Sum" label="[object Object]">
<div><a href="/problems/two-sum">Two Sum</a> </div>
</td>
<td label="[object Object]"><a href="/articles/two-sum"><i class="fa fa-file-text"></i></a></td>
<td value="44.23248982536708" label="[object Object]">44.2%</td>
<td value="[object Object]" label="[object Object]"><span class="label label-success round">Easy</span></td>
<td label="[object Object]"></td>
</tr>
<tr>
<td label="[object Object]"></td>
<td label="[object Object]">2</td>
<td value="Add Two Numbers" label="[object Object]">
<div><a href="/problems/add-two-numbers">Add Two Numbers</a> </div>
</td>
<td label="[object Object]"><a href="/articles/add-two-numbers"><i class="fa fa-file-text"></i></a></td>
<td value="31.20978757805531" label="[object Object]">31.2%</td>
<td value="[object Object]" label="[object Object]"><span class="label label-warning round">Medium</span></td>
<td label="[object Object]"></td>
</tr>
<tr>
<td label="[object Object]"></td>
</tbody>
</table>
上面的HTML表示图像中显示的两行。 我想使用Selenium和Python遍历表行并打印出标题(两个和和和两个数字相加)
但是,表结构太复杂了,我不知道如何生成一个通用函数,使其适用于具有更多行的更大表
有什么帮助吗
如果使用
selenium
并在xpath
之后,它将返回表体行下的所有单元格但是,您需要找出细胞
index
,才能找到细胞内的particular text
或particular tag
在这种情况下,您的
xpath
应该要处理动态元素,归纳
WebdriverWait
总是好的这是您的完整代码
输出将打印在控制台上
相关问题 更多 >
编程相关推荐