21,893
社区成员




header("Content-Type:text/html;charset=utf-8");
$keyword=iconv("utf-8","gb2312",$keyword);
$keyword = str_replace(' ','%20',$keyword);
$url = "http://www.baidu.com/s?wd=$keyword";
$opts = array(
'http'=>array(
'method'=>"GET",
'timeout'=>30,
)
);
$context = stream_context_create($opts);
$cnt=1;
while(($html = @file_get_contents($url,false,$context)) === false && $cnt <= 2 )
$cnt++;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.baidu.com/s?wd=$keyword');
curl_setopt(CURLOPT_USERAGENT, "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.1 (KHTML, like Gecko) Chrome/6.0.437.3 Safari/534.1");
curl_exec($ch);