html - Xpath 组合标签或节点
问题描述
<tr id="computer-report-tbl-row-0" ng-repeat="item in table.data.items" class="ng-scope" style="">
<td id="column-name-0" class="table-cell-md" sc-ellipsis-title="" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
<a ui-sref="devices.computers-details({id:item.id})" route="devices.computers-details({id:item.id})" href="/manage/devices/computers/b97f242b-2ab6-6472-4926-6ca32301c2de">
<ng-transclude><span class="ng-binding ng-scope">hello</span></ng-transclude>
</a>
</td>
<td id="column-last-activity-from-now0" class="table-cell-date-age ng-binding">9 months ago</td>
</tr>
当且仅当xpath 包含与AND与和文本时,我想获取<a>
标记<td>
class = "table-cell-md"
<td>
class='table-cell-date-age ng-binding'
9 months ago
到目前为止,我在想:
//td[@class = 'table-cell-md']|/@*[@class='table-cell-date-age ng-binding' and text()='9 months ago']
解决方案
//td[
@class = 'table-cell-md'
and following-sibling::td[
@class='table-cell-date-age ng-binding' and text() = '9 months ago'
]
]/a
如果following-sibling::td[1][...]
您只想考虑紧随其后的<td>
.
推荐阅读
- python - 在数据帧上应用 lambda 函数时将数据帧作为参数传递
- kotlin - ArchUnit 不区分大小写的名称匹配
- c# - 计算未执行以计算 c#asp.net sql linq 中 2 个日期之间的总天数差异
- javascript - 使用 Apple REST API 登录时无法获取电子邮件地址或 Apple ID
- safari - Safari ITP 2.3:所有脚本可写网站数据的生命周期上限
- r - “`[[<-`(`*tmp*`, i, value = ) 中的错误:在级别 1 没有这样的索引”将 for 循环结果分配给列表
- python - 在 docker build 中运行 pip install requirements.txt 失败
- c# - 如何在 C#.net 中使用 YOLO 提高对象检测的速度
- python - 关键字参数后的位置参数和 * 参数后的常规参数
- c# - 无法从 Linq 翻译 Odata 查询