如何根据 XPath 中嵌套兄弟的值选择元素? [英] How to select an element based on the value of a nested sibling in XPath?
问题描述
在包含大量 DIV 的文档中,我想选择 asset-body
元素内的文本,但前提是 bookmark
链接内的 asset-name entry-title
在 href
值中包含文本 democrat
.
因此,在下面的示例中,包含两个条目"(entry-1
和 entry-2
),我只需要 Jackpot!
因为该条目"中 bookmark
链接的值包含子字符串 democrat
:
http://blahblah.com/politics-democrat
是否可以使用 XPath 执行此操作?
条目 1:(失败:该条目中的 bookmark
链接缺少子字符串 democrat
)
<div class="asset-header"><h2 class="asset-name entry-title"><a rel="bookmark" href="http://blahblah.com/paper-scissors">剪纸</a><div class="asset-content entry-content"><div class="asset-body"><p>纸和剪刀</p>
ENTRY 2: (PASS: bookmark
该条目中的链接包含子字符串 democrat
)
<div class="asset-header"><h2 class="asset-name entry-title"><a rel="bookmark" href="http://blahblah.com/politics-democrat">佩洛西问答</a><div class="asset-content entry-content"><div class="asset-body"><p>头奖!</p>