相关关键词
关于我们
最新文章
PHP CURL采集百度搜寻结果图片不显示问题的解决方法
发布日期:2017-02-03 00:00:00
104
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; ?>