【发布时间】:2013-01-25 05:04:06
【问题描述】:
a.php:
<ul id="ul1">
<li id="pt1">Point 1
<ul id="ul2">
<li id="pt11">Point 1.1</li>
<li id="pt12">Point 1.2</li>
<pre class="CodeDisplay">
some codes
</pre>
<li id="ref">Reference: <a href="link.html" target="_blank">link</a></li>
</ul>
</li>
</ul>
我只想获取 nodeValue“Point 1”。在 JS 中是:
alert(document.getElementsByTagName("li")[0].childNodes[0].nodeValue);
但我想在 PHP (Simple HTML Dom) 中获取 nodeValue;这是另一个 PHP 页面 (b.php) 中的代码 sn-p:
<?php
include('simple_html_dom.php');
$html = file_get_html('http://lifelearning.net63.net/a.php');
// stuck here:
echo $html->getElementsByTagName('ul',0)->getElementsByTagName('li',0)->nodeValue;
//
?>
我使用了 textContent 但它只是提取第 1 点下的内容后代。这不是我想要的。我只想要“第 1 点”。 任何帮助表示赞赏!
【问题讨论】: