<?

//for ($i=230; $i>=0; $i--) {
$url="http://www.aaa-china.org.cn/newList.aspx?nav=4";

$html_content=file_get_contents($url);

preg_match_all('/<\/i><a href="([\s\S]*?)"/',$html_content,$m);



$rows=$m[1];

$data=array();
$cid=538;

foreach  (($rows) as $row){
	     $url="http://www.aaa-china.org.cn/$row";

         $html_content=file_get_contents($url);

	    // $html_content=iconv('GB2312', 'UTF-8', $html_content); //将字符串的编码从GB2312转到UTF-8 
         $html_content = str_replace(array("\r\n", "\r", "\n"), "", $html_content);     //去回车换行 
	
		 preg_match('/<h3 style="color:#323232;font-weight: bold; margin: 20px 0;">([\s\S]*?)<\/h3>/',$html_content,$m);

	     $data['title']=trim($m[1]);
	 
		 preg_match('/时间：([\s\S]*?)<\/span>/',$html_content,$m);
		 $data['addtime']=strtotime($m[1]);

		  preg_match('/<div style="width: 900px; margin: auto; min-height:50px; line-height:25px">([\s\S]*?)<\/div>/',$html_content,$m);
		
		//  preg_match('/简   介：<\/b>([\s\S]*?)<\/p>/',$html_content,$m);
	 //     $data['desc']=$m[1];
		//  preg_match('/关键词：<\/b>([\s\S]*?)<\/p>/',$html_content,$m);
	 //     $data['keyword']=$m[1];
		//  $data['addtime']=time();
		//  preg_match('/<div class="pro_detail">	<ul>([\s\S]*?)<\/ul><\/div>/',$html_content,$m);
  //        $content=$m[1];
		//  preg_match_all('/<img src="([\s\S]*?)"/',$content,$m);
		//  $rs=$m[1];
		 
		//   preg_match("/<li><a href='javascript:;'><img src='..([\s\S]*?)'/",$html_content,$m);
		//    $url="http://www.hnsmzk.com".$m[1];
		//    $data['img']=set_img($url);
		 
		//  $str="";
		 
		// foreach  (array_reverse($rs) as $k=>$r){
		
  //            $ext = strrchr($r,'.');   //获取图片格式
		// 	 $url="http://www.hnsmzk.com".$r;
		// 	  $img_name=set_img($url);
		// 	 $str.="<li><img src='$img_name' /></li>";
		// 	}
	
       //  $url="http://www.bangcheng168.com/news/detail/".$row['UNID'];
//		 $html_content=file_get_contents($url);
//		preg_match('/<div class="content">([\s\S]*?)<\/div>/',$html_content,$m);
		$content=cleae_css($m[1]);
		
		 $content = preg_replace('/http:\/\/www.cecpsp.org.cn\/(.*)\.html/', '/', $content);  //去掉外链
		  $content = preg_replace('/http:\/\/www.cecpsp.org.cn\//', '/', $content);  //去掉外链
		   $content = preg_replace('/http:\/\/www.cecpsp.org.cn/', '/', $content);  //去掉外链
		$data['content']=trim($content);
		
		$data['hits']=rand(1000,6666);
		$data['cid']=$cid;
 
        $id=$duoduo->insert("article",$data);
		if ($id)
	        echo "添加成功".$data['title']."<br>";
	
	    ob_flush();  
      flush();  
      sleep(1); 
		
		 
	} 
//}
	exit();

		function cleae_css($content){
	
	
	$content = preg_replace("/<a[^>]*>/i", "", $content);

$content = preg_replace("/<\/a>/i", "", $content);

//$content = preg_replace("/<p[^>]*>/i", "", $content);

//$content = preg_replace("/<\/p>/i", "", $content);

$content = preg_replace("/<!--[^>]*-->/i", "", $content);//注释内容

$content = preg_replace("/style=.+?['|\"]/i",'',$content);//去除样式

$content = preg_replace("/class=.+?['|\"]/i",'',$content);//去除样式

$content = preg_replace("/id=.+?['|\"]/i",'',$content);//去除样式

$content = preg_replace("/lang=.+?['|\"]/i",'',$content);//去除样式

$content = preg_replace("/width=.+?['|\"]/i",'',$content);//去除样式

$content = preg_replace("/height=.+?['|\"]/i",'',$content);//去除样式

$content = preg_replace("/border=.+?['|\"]/i",'',$content);//去除样式

$content = preg_replace("/face=.+?['|\"]/i",'',$content);//去除样式

$content = preg_replace("/face=.+?['|\"]/",'',$content);//去除样式 只允许小写 正则匹配没有
return $content;
	
	}
	function set_img($url){
		  $ext = strrchr($url,'.');   //获取图片格式
		   $img = file_get_contents($url); 
		   
		    $img_name="cai/".getMillisecond().$ext;
			sleep(1);
			file_put_contents($img_name,$img); 
			return "/".$img_name;
		}
	function getMillisecond() { 
list($s1, $s2) = explode(' ', microtime()); 
return (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000); 
} 
	
	function jian_cur($url,$cookie,$post_fields){
		
         $ch= curl_init();
		 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
         curl_setopt($ch, CURLOPT_URL,$url);
         curl_setopt($ch, CURLOPT_COOKIE, $cookie);
		// curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:111.222.333.4', 'CLIENT-IP:111.222.333.4'));  
         curl_setopt($ch, CURLOPT_REFERER, "http://www.tiangua.com/");
         curl_setopt($ch, CURLOPT_HEADER, false);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		 $useragent="Mozilla/5.0 (Windows NT 5.1; rv:30.0) Gecko/20100101 Firefox/30.0";
         curl_setopt ($ch, CURLOPT_USERAGENT, $useragent);
         curl_exec($ch);
         $tempCn = curl_multi_getcontent($ch);
		 return $tempCn;
		}
?>