我想在一个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 Child">Rachel Zoe Expecting Second 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 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');
答案 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');