Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HtmlAgilityPack/XPath查找特定标记之后/下一个标记之前的所有事件_Xpath_Html Agility Pack - Fatal编程技术网

HtmlAgilityPack/XPath查找特定标记之后/下一个标记之前的所有事件

HtmlAgilityPack/XPath查找特定标记之后/下一个标记之前的所有事件,xpath,html-agility-pack,Xpath,Html Agility Pack,敏捷新手。给定输入文本: <html> ... Lots of html here... <label class="list_item_title">Yes</label><br /><br /> <div class="list_item"> <div style="width:425px;" class="left"><a href="/xyz">HIT1<

敏捷新手。给定输入文本:

<html>
  ... Lots of html here...
  <label class="list_item_title">Yes</label><br /><br />
    <div class="list_item">
        <div style="width:425px;" class="left"><a href="/xyz">HIT1</a>  (2012)</div>
        <div style="width:190px;" class="right"></div>
    </div>
    <div class="list_item">
        <div style="width:425px;" class="left"><a href="/abc">HIT2</a>  (2012)</div>
        <div style="width:190px;" class="right"></div>
    </div>
  <label class="list_item_title">No</label><br /><br />
  <div class="list_item">
        <div style="width:425px;" class="left"><a href="/xyz">IGNORE</a>  (2012)</div>
        <div style="width:190px;" class="right"></div>
  </div>
  ... Lots of html here...
</html>

... 这里有很多html。。。
是

(2012) (2012) 否

(2012) ... 这里有很多html。。。
我想打1号和2号


基本上,该算法是在label节点(class=“list\u item\u title”)之后查找所有A的innerText,其中innerText=“Yes”

此XPath表达式适用于您的示例:

//a[preceding::label[1][text()="Yes"]]/text()

它查找其前一个
标签
包含
Yes
的所有
a
,并返回其文本()。[1]后面的标签是我所缺少的