【发布时间】:2015-08-29 06:16:26
【问题描述】:
我有以下html:
<div id="myID">
<p>I want this</p>
<p>and I want this</p>
<div>
<p>I don't want this</p>
</div>
</div>
我只想提取第一级<p>...</p> 元素。
我尝试过使用出色的 simple_html_dom 库,例如$html->find('#myID p') 但在上述情况下,这会找到所有三个 <p>...</p> 元素
有没有更好的方法来做到这一点?
【问题讨论】:
-
尝试在您的选择器中使用
children方法(如果该对象有这样的方法)或>:$html->find('#myID > p') -
仍然返回所有段落
标签: php