Xpath在一个nodeValue中获得多个p标记

时间:2013-09-03 20:49:12

标签: php xpath

我想在一个nodeValue中检索div class="post"中的所有p标记。这是我的HTML:

<div class="blogEntry expecting featured featured-post-today%e2%80%99s-top-story first">
<h2><a href="/2013/09/03/rachel-zoe-pregnant-expecting-second-child/" rel="bookmark" title="Permanent Link to Rachel Zoe Expecting Second&nbsp;Child">Rachel Zoe Expecting Second&nbsp;Child</a></h2>
<div class="post">
    <p>Sometext</p>
    <p>someothertext</p>
</div>
<div class="blogEntry expecting featured featured-post-today%e2%80%99s-top-story first">
<h2><a href="someurl" rel="bookmark" title="Permanent Link to Rachel Zoe Expecting Second&nbsp;Child">sometitle</a></h2>
<div class="post">
    <p>Sometext</p>
    <p>someothertext</p>
</div>
</div>

这是我的xpath:

$finder->query('//div[contains(@class,"blogEntry")]//div[@class="post"]//p');

2 个答案:

答案 0 :(得分:1)

非常难看,但希望它是你要找的那个 -

//div[contains(@class,"blogEntry")]/div[@class="post"]/concat(p[1]," ",p[2])

//div[contains(@class,"blogEntry")]/div[@class="post"]/string-join((p[1],p[2])," ")

<强>输出

Sometext someothertext
Sometext someothertext

答案 1 :(得分:0)

应该是:

$finder->query('//div[contains(@class,"blogEntry")]/div[@class="post"]/p');