1. 程式人生 > >PHP 百度關鍵字

PHP 百度關鍵字

<?php
header("Content-type:text/html;charset=utf-8");
//PC百度搜索
$key = "澳門金沙";
$url = 'http://www.baidu.com/s?word='.$key."&rn=50";
function curl_list($url){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
$content = curl_exec($ch);
curl_close($ch);
$preg = "/<h3.*?>(.*?)<\/h3>/ism";
preg_match_all($preg,$content,$res);
foreach ($res['1'] as $key => $value) {
$preg = "/<a.*?>(.*?)<\/a>/ism";
preg_match_all($preg,$value,$re);
if($re['1']['0']){
$list[] = strip_tags($re['1']['0']);
}

}
return $list;
}
$result = curl_list($url);
echo "<pre>";
var_dump($result);