1.根据关键字采集百度搜寻结果
根据关键字采集百度搜寻结果,可以使用curl实现,代码如下:<?php
function doCurl($url, $data=array(), $header=array(), $timeout=30){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
$response = curl_exec($ch);
if($error=curl_error($ch)){
die($error);
}
curl_close($ch);
return $response;
}
$wd = '仙剑奇侠传';
$url = 'http://www.baidu.com/s?wd='.urlencode($wd);
$data = array();
$header = array();
$response = doCurl($url, $data, $header, 5);
echo $response;
?>
输出后发现有部分图片不能显示