我使用下面的代码解析DOM文档,但最后我得到的错误 “google.ac”为空或不是对象 线402 焦炭1PHP PRODOM解析错误
我想什么,第402行包含标签和很多“;”, 我该如何解决这个问题?
<?php
//$ch = curl_init("http://images.google.com/images?q=books&tbm=isch/");
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://images.google.com/images?q=books&tbm=isch/");
curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
$data = curl_exec($ch);
curl_close($ch);
$dom = new DOMDocument();
$dom->loadHTML($data);
//@$dom->saveHTMLFile('newfolder/abc.html')
$dom->loadHTML('$data');
// find all ul
$list = $dom->getElementsByTagName('ul');
// get few list items
$rows = $list->item(30)->getElementsByTagName('li');
// get anchors from the table
$links = $list->item(30)->getElementsByTagName('a');
foreach ($links as $link) {
echo "<fieldset>";
$links = $link->getElementsByAttribute('imgurl');
$dom->saveXML($links);
}
?>
'$ dom-> loadHTML('$ data1');'肯定是错误的。 – chx 2012-01-15 14:45:27
那我该怎么办呢?我该怎么办?我的基本目标是从代码中获取内容,并可能保存它。 – 2012-01-15 14:51:46
对不起,我已经得到了您的要点chx,它的$数据。当我尝试这个时,我试图使用get_matche()来提取只需要的标签,但是当粘贴代码在这里时,我忘了更改变量..现在更新,谢谢亲爱的 – 2012-01-15 17:55:29