public function index(){
$url = "http://www.zyctd.com/gqqg/" ;
$supplyDB = M( 'supply' );
$urlList = array ();
$array = array ();
for ( $x =1; $x <=1; $x ++) {
array_push ( $urlList , "http://www.zyctd.com/gqqg-p" . $x . ".html" );
};
foreach ( $urlList as $v ){
$curPageList = $this ->getInfo( $v );
array_push ( $array , $curPageList );
};
foreach ( $array as $v ){
foreach ( $v as $vv ){
$data = array ();
$data [ 'title' ] = $vv [ 'title' ];
$data [ 'weight' ] = $vv [ 'weight' ];
$data [ 'add_time' ] = $vv [ 'add_time' ];
$data [ 'url' ] = $vv [ 'url' ];
echo "<p><span style='display:inline-block; width:110px;'>" . $vv [ 'title' ]."</span>
<span style= 'display:inline-block; width:110px;' > ".$vv['weight']." </span>
<span style= 'display:inline-block; width:110px;' > ".$vv['add_time']." </span>
<span style= 'display:inline-block; width:110px;' > ".$vv['url']." </span></p>";
}
}
}
private function getInfo( $url ){
$html = $this ->getHtml( $url );
$array = array ();
preg_match_all( "#<divclass=\"sulist_title\"><i></i><span>(.*?)</span></div>#" , $html , $matches );
$all_title = $matches [1];
preg_match_all( "#<i>发布时间:</i><span>(.*?)</span>#" , $html , $matches );
$all_time = $matches [1];
preg_match_all( "#<i>求购数量:</i><span>(.*?)</span>#" , $html , $matches );
$all_weight = $matches [1];
preg_match_all( "#<atarget=\"_blank\"href=\"(.*?)\">#" , $html , $matches );
$all_url = $matches [1];
foreach ( $all_title as $k => $v ){
$arr = array ();
$arr [ 'title' ] = $v ;
$arr [ 'weight' ] = $all_weight [ $k ];
$arr [ 'add_time' ] = $all_time [ $k ];
$arr [ 'url' ] = $all_url [ $k ];
array_push ( $array , $arr );
}
return $array ;
}
private function getHtml( $url ){
$html = file_get_contents ( $url );
$html = preg_replace( "#\n#" , "" , $html );
$html = preg_replace( "#\r#" , "" , $html );
$html = preg_replace( "#\\s#" , "" , $html );
return $html ;
}
|