我想要检索位于此span类属性中的正文文本。使用DOM解析PHP(无结果)
<span id="" style="color:#525B64;">The quick brown fox jumped over the lazy dog.</span>
我在我的网络服务器上测试过它,我没有收到任何错误,但是网页是空白的。我对此很陌生,所以我不知道该从哪里出发。
这是我的代码。
<?php
// Load remote file, supress parse errors
libxml_use_internal_errors(TRUE);
$dom = new DOMDocument;
$dom->loadHTMLFile('http://somewebpage.com');
libxml_clear_errors();
// use XPath to find all nodes with a class attribute of header
$xp = new DOMXpath($dom);
$nodes = $xp->query('//span[@class="msgBody"]');
// output first item's content
echo $nodes->item(0)->nodeValue;
?>
什么是您试图访问的实际页面?据我所知,此代码有效。 – lonesomeday 2011-02-02 01:24:51