Public functionSpider_j ($page) { $url= "HTTP://AAA/BBB".$page." _0/"; $fcontents=file_get_contents($url); $table _data=Preg_match_all(' #<table> (. *?) </table> #si ',$fcontents,$match); $table _data=$match[0] [0]; $table _array=Explode(' <tr> ',$table _data); $data=Array(); for($i= 2;$i<Count($table _array);$i++){ $data[$i] =Explode(' </td> ',$table _array[$i]); for($j= 0;$j<Count($data[$i]);$j++){ $data[$i][$j] =Preg_replace('/\s (? =\s)/', ',Trim(Strip_tags($data[$i][$j]))); } $data[$i][6] =Date(' y-m-d '); } $kname=Array(' ID ', ' gamename ', ' gategory ', ' BETA ', ' DATA ', ' DOWNLOAD ', ' thedate '); foreach($data as $key=>&$val){ $val=Array_combine($kname,$val); } for($i= 2;$i< (Count($data) +2);$i++){ $this->db06->insert (' Tbl_j ',$data[$i]); } } Public functionSpider () { for($i= 1;$i<11;$i++){ $this->spider_j ($i); } }
Logic: Read the Code of the Web page into a string, filter out the specified data through regular expressions, and then become a two-dimensional array, inserted into the database.
PHP crawling table data in Web pages