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「ポイント1」のみを取得したいと思います。JS では、次のようになります。
alert(document.getElementsByTagName("li")[0].childNodes[0].nodeValue);
しかし、PHP (Simple HTML Dom) で nodeValue を取得したいと思います。別の PHP ページ (b.php) のコード スニペットを次に示します。
<?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」だけ欲しい。どんな助けでも大歓迎です!