1

我想div class="post"在一个 nodeValue 中检索所有 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');
4

2 回答 2

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
于 2013-09-03T21:25:34.683 回答
0

它应该是 :

$finder->query('//div[contains(@class,"blogEntry")]/div[@class="post"]/p');
于 2013-09-03T20:53:00.550 回答