【免费开源】利用云数据API接口,开发属于自己的采集器
复制下面的代码,保存为一个php文件即可,可以把代码封装一下,变成自己的东西!
- <?phpheader("Content-type: text/html; charset=utf-8");function get_sign($dataArr) //计算签名验证的函数{ if(!is_array($dataArr)) { return 'no'; } else { ksort($dataArr, SORT_STRING); $string1 = ''; foreach ($dataArr as $k => $v) { $v=urlencode($v); $string1 .= "{$k}={$v}&"; } return strtoupper(md5($string1)); }}function get_json_data($dataUrl) // 根据接口地址,转换成具体列表内容,展示结果{ $nowTime=time(); $tokenStr=file_get_contents('./appid.txt'); // 读取保存的appid和对应的密钥 $tokenArr=explode('_ZW_',$tokenStr); $appid=$tokenArr[0]; $appid_key=$tokenArr[1]; $dataJson=file_get_contents($dataUrl); $dataJson=trim($dataJson); $dataNewsArr=json_decode($dataJson,true); $result='<hr><h2>下面是结果内容</h2><hr><p><br></p>'; $result=$result.'<table border=1 cellpadding=12 ; $result=$result.'<tr><th>一键采集</th><th>标题</th><th>链接地址</th><th>发布时间</th></tr>'; foreach($dataNewsArr as $item) { $signArr=array(); $signArr['url']=urldecode($item['fromurl']); $signArr['appid']=$appid; $signArr['t']=$nowTime; $signArr['appsecret']=$appid_key; // 密钥仅用于计算签名,不要公开,私密 $sign=get_sign($signArr); $result=$result.'<tr ; $result=$result.'<td nowrap><a href="./sdk_demo.php?ac=content&url='.urlencode($item['fromurl']).'&appid='.$appid.'&t='.$nowTime.'&sign='.$sign.'"> 点击采集 </a></td>'; $result=$result.'<td>'.$item['title'].'</td>'; $result=$result.'<td><a href="'.$item['fromurl'].'" target="_blank">'.$item['fromurl'].'</a></td>'; $result=$result.'<td nowrap>'.date('Y-m-d H:i:s',$item['sendtime']).'</td>'; $result=$result.'</tr>'; } $result=$result.'</table>'; return $result;}if(!empty($_GET['ac']) && $_GET['ac']=='register'){ if(!file_exists('./appid.txt')) { $appid=php_uname('s').php_uname('n').php_uname('m'); // 根据服务器的特征,生成唯一appid,请求获得密钥之后,保存到本地 $appid=$appid.__DIR__; $appid=md5($appid); $appid_key=file_get_contents("http://api.zhiwu55.net/v1/catch_data/register/?appid=".$appid); $dataStr=$appid.'_ZW_'.$appid_key; file_put_contents('./appid.txt',$dataStr); //生产环境中,上线了,千万不要这样保存appid和密钥,相当于公开暴露出去了 } $result='<hr><h2>下面是结果内容</h2><hr><p><br></p>注册appid成功!已经保存到appid.txt文件中'; }if(!empty($_GET['ac']) && $_GET['ac']=='content'){ $fromurl=urlencode($_GET['url']); $dataUrl="http://api.zhiwu55.net/v1/catch_data/content/?url={$fromurl}&appid={$_GET['appid']}&t={$_GET['t']}&sign={$_GET['sign']}"; $content=file_get_contents($dataUrl); if($content=='Requests are too frequent') { $result='<h1>采集过于频繁!</h1>'; } elseif(strlen($content)<50) { $result='<h1>'.$content.'</h1>'; } elseif(stripos($content,'__zhiwu55.com__')!==false) { $firstPost=substr($content,0,strpos($content,'__zhiwu55.com__')); $comment=substr($content,strpos($content,'__zhiwu55.com__')+15); $comment=str_replace('__zhiwu55.cn__','</li><li>',$comment); $result='<hr><h2>下面是结果内容</h2><hr><p><br></p>'.$firstPost.'<br><br><strong>评论如下:</strong><br><br><li>'.$comment.'</li>'; } else { $result='<hr><h2>下面是结果内容</h2><hr><p><br></p>'.$content; }}if(!empty($_GET['ac']) && $_GET['ac']=='search_keyword' && !empty($_GET['keyword'])){ $tokenStr=file_get_contents('./appid.txt'); // 读取保存的appid和对应的密钥 $tokenArr=explode('_ZW_',$tokenStr); $appid=$tokenArr[0]; $dataUrl="http://api.zhiwu55.net/v1/catch_data/search/?appid={$appid}&keyword=".urlencode($_GET['keyword']); $result=get_json_data($dataUrl);} if(!empty($_GET['ac']) && $_GET['ac']=='hotnews'){ $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/hotnews_json.html');}if(!empty($_GET['ac']) && $_GET['ac']=='top_news'){ $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/updatenews_json.html'); }if(!empty($_GET['ac']) && $_GET['ac']=='toutiao'){ $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/toutiao.com_json.html'); }if(!empty($_GET['ac']) && $_GET['ac']=='thepaper'){ $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/thepaper.cn_json.html'); }if(!empty($_GET['ac']) && $_GET['ac']=='sohu'){ $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/sohu.com_json.html'); }if(!empty($_GET['ac']) && $_GET['ac']=='sina'){ $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/sina.com.cn_json.html'); }if(!empty($_GET['ac']) && $_GET['ac']=='qq'){ $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/qq.com_json.html'); }if(!empty($_GET['ac']) && $_GET['ac']=='myzaker'){ $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/myzaker.com_json.html'); }if(!empty($_GET['ac']) && $_GET['ac']=='guokr'){ $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/guokr.com_json.html'); }if(!empty($_GET['ac']) && $_GET['ac']=='163'){ $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/163.com_json.html'); }if(!empty($_GET['ac']) && $_GET['ac']=='keyword01'){ $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/E4BD93E882B2_json.html'); }if(!empty($_GET['ac']) && $_GET['ac']=='keyword02'){ $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/E8B4A2E7BB8F_json.html'); }if(!empty($_GET['ac']) && $_GET['ac']=='keyword03'){ $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/E6989FE5BAA7_json.html'); }if(!empty($_GET['ac']) && $_GET['ac']=='keyword04'){ $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/E59BBDE99985_json.html'); }if(!empty($_GET['ac']) && $_GET['ac']=='keyword05'){ $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/E5869BE4BA8B_json.html'); }if(!empty($_GET['ac']) && $_GET['ac']=='keyword06'){ $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/E5BDA9E7A5A8_json.html'); }if(!empty($_GET['ac']) && $_GET['ac']=='keyword07'){ $result=get_json_data('http://api.zhiwu55.net/v1/catch_data/batch_run/E7949FE6B4BB_json.html'); }?><!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0,viewport-fit=cover"></head><body no'; } else { ksort($dataArr, SORT_STRING); $string1 = ''; foreach ($dataArr as $k => $v) { $v=urlencode($v); $string1 .= "{$k}={$v}&"; } return strtoupper(md5($string1)); }}$mySignArr=array();$mySignArr['url']=urldecode($fromurl); //通过接口返回的fromurl链接地址$mySignArr['appid']='ZW3456789812X45678901234567890a1'; // 注册的appid$mySignArr['t']=time(); //当前时间戳$mySignArr['appsecret']='OuHZ552V20hi5ie3HCKTtyez3HR5ukhc'; // 密钥$mySignStr=get_sign($signArr); // 根据参数计算出来的签名$dataUrl="http://api.zhiwu55.net/v1/catch_data/content/?url={$fromurl}&appid=ZW3456789812X45678901234567890a1&t={$mySignArr['t']}&sign={$mySignStr}";echo file_get_contents($dataUrl);-----------------------------------------------------------------------------接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/updatenews_json.html接口说明:获取全网最新的内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容-----------------------------------------------------------------------------接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/hotnews_json.html接口说明:今日热搜榜单火爆全网的内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容-----------------------------------------------------------------------------接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/toutiao.com_json.html接口说明:今日头条最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容-----------------------------------------------------------------------------接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/thepaper.cn_json.html接口说明:澎拜新闻最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容-----------------------------------------------------------------------------接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/sohu.com_json.html接口说明:搜狐最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容-----------------------------------------------------------------------------接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/sina.com.cn_json.html接口说明:新浪最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容-----------------------------------------------------------------------------接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/qq.com_json.html接口说明:腾讯网最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容-----------------------------------------------------------------------------接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/myzaker.com_json.html接口说明:扎客新闻网最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容-----------------------------------------------------------------------------接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/guokr.com_json.html接口说明:果壳网最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容-----------------------------------------------------------------------------接口地址:http://api.zhiwu55.net/v1/catch_data/batch_run/163.com_json.html接口说明:网易最新内容,直接访问即可,返回json数据格式,隔一段时间自动更新内容********/?></body></html>