我使用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);
}
}
?>
編輯
其實是抱歉,行是爲了測試時,我曾評論其他的東西...我刪除了它在這裏仍然有錯誤,但。