php抓取网站内容,获取通达OA官网最新用户,判断页面是否能访问,php正则

来源:互联网 发布:bigworld源码 编辑:程序博客网 时间:2024/06/05 14:56
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>名单显示</title></head><body><style>li{ font-size:13px;}li.red{color:#F00;}#mingdan{margin-left:5px;}</style><?set_time_limit(0); //$now=date("Y-m-d");//$count=0;<span style="white-space: pre;"></span>$a=2;<span style="white-space:pre"></span>//获取所有的最新用户和事业单位$url1 = "http://www.tongda2000.com/index.php"; $ch=curl_init($url1);curl_setopt($ch, CURLOPT_URL,$url1);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  //获得结果不直接输出curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);$out_put=curl_exec($ch);$str=curl_getinfo($ch);//echo $str['http_code'];   if($str['http_code']==200){$a=1;}else{$a=2;}//echo "<hr>";if($a==1){$contents1 = file_get_contents($url1); //如果出现中文乱码使用下面代码 if($contents1){$getcontent = iconv("gb2312", "utf-8",$contents); //echo $contents;  $mode1 = "/<div class=\"signing-text\">(.*)<div id=\"index-con1\">/is"; preg_match_all($mode1,$contents1,$matches1);//获取最新用户的//print_r($matches1);$zxyh_str=$matches1[0][0];//获取最新用户的名称//echo $zxyh_str;  //最新用户$mode2 = "/<ul>(.*)<\/ul>/is"; preg_match_all($mode2,$zxyh_str,$matches2);//print_r($matches2);$zxyh_str2=$matches2[0][0];echo "<div id=\"mingdan\">";echo iconv("gbk","UTF-8",$zxyh_str2);echo "</div>";}}   <span style="white-space:pre"></span>curl_close($ch);//echo $out_put;?></body></html>

1 0
原创粉丝点击