我正在使用简单的 html dom 解析器从网站上抓取产品,我为此编写了以下代码
<?php
error_reporting(E_ALL);
require_once('lib/simple_html_dom.php');
set_time_limit(0);
ini_set('memory_limit', '1024M');
ini_set('max_input_time ', '99999');
$url='http://www.yourpoolhq.com/pool-supplies/aboveground/pool-liners/round/unibead.html';
$html = file_get_html($url);
if(is_object($html)){
foreach ( $html->find('div.category-products') as $elem ){
$data = $elem->innertext;
$strdata = str_get_html($data);
foreach ($strdata->find('a') as $a) {
if($a->plaintext!=''){
get_detail_page($a->href);
flush();
}
flush();
}
unset($data);
unset($strdata);
}
$html->clear();
unset($html);
}
function get_detail_page($href){
$details = file_get_html($href);
if(is_object($details)){
foreach ($details->find('h1') as $ess ) {
//print_r($ess); this has data
echo $ess->plaintext; // not getting this, Why this is not printing. x-(
flush();
}
$details->clear();
unset($details);
}
flush();
}
?>
没有得到我在这里做错了什么。任何想法的家伙。
编辑:我已经更新了在某些地方添加的代码并注释了错误部分。