我使用PHP和XPath爬进一个网站,我自己的(刚才抓取的HTML不会到服务器),但我得到这个错误:PHP和XPath的问题
Catchable fatal error: Object of class DOMNodeList could not be converted to string in C:\wamp\www\crawler.php on line 46
我已经尝试过呼应刚该行看到我得到什么,但我只会得到相同的错误,我也试着用google搜索错误,但我最终结束了在PHP文档,发现我的例子是完全一样的PHP文档中的除外我正在使用HTML而不是XML ......所以我不知道有什么问题......这是我的代码...
<?php
$html = file_get_contents('http://miurl.com/mipagina#0');
// create document object model
$dom = new DOMDocument();
// load html into document object model
@$dom->loadHTML($html);
// create domxpath instance
$xPath = new DOMXPath($dom);
// get all elements with a particular id and then loop through and print the href attribute
$elements = $xPath->query("//*[@class='nombrecomplejo']");
if ($elements != null) {
foreach ($elements as $e) {
echo parse_str($e);
}
}
?>
编辑
其实是抱歉,行是为了测试时,我曾评论其他的东西...我删除了它在这里仍然有错误,但。