In the project to use the collected data, so first take CSDN blog to try. This library uses the simple HTML DOM (official website), which makes it easy to traverse HTML documents.
<?PHPinclude_once(' simple_html_dom.php '); Header(' Content-type:text/html;charset=utf-8 '); $html= file_get_html (' http://blog.csdn.net/szy361 '); $res=$html->find (' #hotarticls ul.panel_body li A[title] ');//get the title of a under the UL tag Class Panel_bodya under Id=hotarticls $span=$html->find (' #hotarticls ul.panel_body li span ');//get span foreach($res as $element){ $arr[] =$element->title. ' + '.$element->href;//Connect the title value and the value of the href through + . } foreach($span as $e){ $BRR[] =$e->innertext;//get an array of values under span } //make two arrays into a new two-dimensional array for($i= 0;$i<Count($res);$i++){ $CRR[] =Explode(' + ',$arr[$i]); $CRR[$i][] =$BRR[$i]; } return $CRR;
Extended:
Getting started with PHP simple HTML DOM Parser