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
XPATH-在某个html元素之后停止刮取_Xpath - Fatal编程技术网

XPATH-在某个html元素之后停止刮取

XPATH-在某个html元素之后停止刮取,xpath,Xpath,我使用此XPATH查询尝试从“ASQ套餐价格”中获取前三项: 但它也抓住了其他3个项目,所以我最终 例1 例2 例3 例4 例5 例6 我只想: 例1 例2 例3 如何防止XPATH删除我不想要的三个标记?在本例中,它似乎需要停止在标记处 <div itemprop="articleBody"> <h2>ASQ Package Price</h2> <p class="">Example 1</p&g

我使用此XPATH查询尝试从“ASQ套餐价格”中获取前三项:

但它也抓住了其他3个项目,所以我最终

例1 例2 例3 例4 例5 例6

我只想:

例1 例2 例3

如何防止XPATH删除我不想要的三个标记?在本例中,它似乎需要停止在

标记处

<div itemprop="articleBody">

<h2>ASQ Package Price</h2>
<p class="">Example 1</p>
<p class="">Example 2</p>
<p class="">Example 3</p>

<hr>

<h2>ASQ Package Features&nbsp;</h2>

<p class="">Example 4</p>
<p class="">Example 5</p>
<p class="">Example 6</p>

</div>

ASQ套餐价格

示例1

示例2

示例3


ASQ软件包功能

示例4

示例5

示例6

使用xpath 2.0:

//h2/following-sibling::p intersect //hr/preceding-sibling::p
使用xpath 1.0:

//h2/following-sibling::p[not(preceding-sibling::hr)] 
使用

     (//h2[starts-with(., 'ASQ Package')])[1]/following-sibling::hr[1]
                                                         /preceding-sibling::p
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

  <xsl:template match="/">
     <xsl:copy-of select=
     "(//h2[starts-with(., 'ASQ Package')])[1]
                    /following-sibling::hr[1]
                        /preceding-sibling::p"/>"/>
  </xsl:template>
</xsl:stylesheet>
<p class="">Example 1</p>
<p class="">Example 2</p>
<p class="">Example 3</p>

使用XSLT进行验证

     (//h2[starts-with(., 'ASQ Package')])[1]/following-sibling::hr[1]
                                                         /preceding-sibling::p
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

  <xsl:template match="/">
     <xsl:copy-of select=
     "(//h2[starts-with(., 'ASQ Package')])[1]
                    /following-sibling::hr[1]
                        /preceding-sibling::p"/>"/>
  </xsl:template>
</xsl:stylesheet>
<p class="">Example 1</p>
<p class="">Example 2</p>
<p class="">Example 3</p>
然后我们选择它下面的第一个同级

    (//h2[starts-with(., 'ASQ Package Features')])[1]/following-sibling::hr[1]
然后我们选择它前面的所有同级元素:

 (//h2[starts-with(., 'ASQ Package')])[1]/following-sibling::hr[1]
                                                     /preceding-sibling::p