You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用XPath结合多条件提取符合要求的链接(排除特定元素)

解决XPath查询问题

最终可用的XPath语句

//div[@data-test="cond1" and not(.//img[@class="cond3"])]/a[@class="cond2"]/@href

语句拆解

  • 定位符合要求的父容器://div[@data-test="cond1" and not(.//img[@class="cond3"])]
    • @data-test="cond1":筛选出带有指定属性的div元素
    • not(.//img[@class="cond3"]):排除掉内部包含class为cond3的img后代元素的div
  • 定位目标链接标签:/a[@class="cond2"]
    • 在上述符合条件的父div下,找到带有class为cond2的a标签
  • 提取链接值:/@href
    • 获取该a标签的href属性内容,即你需要的目标链接

内容的提问来源于stack exchange,提问作者Christoph Zogg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 18:45:32