Xpath 在一个 nodeValue 中获取多个 p 标签 [英] Xpath getting multiple p tags in one nodeValue

查看:55
本文介绍了Xpath 在一个 nodeValue 中获取多个 p 标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

<div class="blogEntry 期待精选 features-post-today%e2%80%99s-top-story first"><h2><a href="/2013/09/03/rachel-zoe-pregrant-expecting-second-child/" rel="bookmark" title="Rachel Zoe 期待第二个孩子的永久链接">Rachel Zoe 期待第二个孩子</a></h2><div class="post"><p>Sometext</p><p>其他文本</p>

<div class="blogEntry 期待精选精选后今天%e2%80%99s-top-story first"><h2><a href="someurl" rel="bookmark" title="Rachel Zoe 期待第二个孩子的永久链接">sometitle</a></h2><div class="post"><p>Sometext</p><p>其他文本</p>

这是我的 xpath:

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

解决方案

应该是:

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

I'd like to retrieve all of the p tags within div class="post" in one nodeValue. Here is my 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>

Here is my xpath:

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

解决方案

It should be :

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

这篇关于Xpath 在一个 nodeValue 中获取多个 p 标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆