我可以使用同级兄弟功能
获得两个值吗?上一个兄弟姐妹:: td =“半场角球”和“角球”
HTML代码
<tr>
<td width="295" align="right" class="bg2">
<div class="barBg2">
<div class="info" style="width:82%;">
</div>
</div>
</td>
<td width="50" align="center" class="bg2">14</td>
<td width="110" align="center" class="bg4">角球</td>
<td width="50" align="center" class="bg2">3</td>
<td width="295" align="left" class="bg2">
<div class="barBg">
<div class="info" style="width:18%;"></div>
</div></td>
</tr>
<tr>
<td width="295" align="right" class="bg1">
<div class="barBg2">
<div class="info" style="width:79%;"></div>
</div>
</td>
<td width="50" align="center" class="bg1">11</td>
<td width="110" align="center" class="bg3">半場角球</td>
<td width="50" align="center" class="bg1">3</td>
<td width="295" align="left" class="bg1">
<div class="barBg">
<div class="info" style="width:21%;"></div>
</div>
</td>
Python代码
texts = [td.text for td in driver.find_elements_by_xpath('//td[(preceding-sibling::td="半場角球" and "角球") and not(div)]')]
预期产量
3 3
答案 0 :(得分:3)
尝试这个
//td[(preceding-sibling::td="半場角球" or preceding-sibling::td="角球") and not(div)]