$get=$_GET["url"];
$url="https://www.baidu.com/s?wd=site%3A".$get; //从外部获取变量
$UserAgent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506; .NET CLR 3.5.21022; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_ENCODING, '');
curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($curl);
//上面获取网站源码
preg_match('/该网站共有(.*)个网页被百度收录/isU', $data, $count);
if (empty($count[1])) { //empty判断空数组
preg_match('/找到相关结果数约(.*)个/isU', $data, $count1);
if(empty($count1[1])){
echo '查询失败!';
}
else{
echo '百度收录:'.$count1[1];
}
}
else{
echo '百度收录:'.$count[1];
}
curl_close($curl); //关闭cURL资源,并释放系统资源 |