【发布时间】:2010-10-07 14:50:02
【问题描述】:
我正在使用 PHP 和 xPath 爬入我拥有的网站(只是爬取不进入服务器的 html)但我收到此错误:
可捕获的致命错误:类对象 DOMNodeList 无法转换为 C:\wamp\www\crawler.php 中的字符串 第 46 行
我已经尝试回显该行以查看我得到了什么,但我也会得到同样的错误,我也尝试用谷歌搜索错误,但最后我在 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);
}
}
?>
编辑
实际上是的,抱歉,当我评论其他内容时,该行是为了测试...我在这里删除它仍然有错误。
【问题讨论】: