使用说明
解压压缩包里面的hotlist.php文件到网站目录
然后输入参数输入?type
参数内容 zhihuhot(知乎热榜) weibohot(微博热搜) bdhot(百度热搜)
注意事项
如果上传了没法使用 请检查服务器环境
1.是否为国内服务器(不是必须)
2.PHP环境是否为7-8
3.服务器是否正确安装环境
hotsearch
源代码:
<?php /** * 作者:苏晓晴 * 作者QQ:3074193836 * 热搜榜 (知乎/微博/百度) * 免费源码 无限制 * 个人API api.qqsuu.cn * 个人博客 www.toubiec.cn */ header('Content-Type:application/json; charset=utf-8'); $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : ""; if (empty($type)) { die( json_encode( array( 'success' => false, 'msg' => '参数禁止为空!' ),480) ); //根据参数自动判断 }elseif($type == "zhihuhot"){ $types = "zhihu"; }elseif($type == "weibohot"){ $types = "weibo"; }elseif($type == "bdhot"){ $types = "baidu"; }else{ die( json_encode( array( 'success' => false, 'msg' => '请输入正确的参数!' ),480) ); } $types(); //知乎热搜榜解析实例 function zhihu(){ $header = ['User-Agent:Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1']; $json = curl('https://www.zhihu.com/hot',$header); preg_match('/<script id=\"js-initialData\" type=\"text\/json\">(.*?)<\/script>/', $json, $json_data); $json_datas = json_decode($json_data[1], true); //循环 foreach($json_datas['initialState']['topstory']['hotList'] as $key => $value){ $data[$key] = array( 'index'=>$key + 1, 'title'=>$value['target']['titleArea']['text'], 'pic'=>$value['target']['imageArea']['url'], 'hot'=>$value['target']['metricsArea']['text'], 'desc'=>$value['target']['excerptArea']['text'], 'url'=>$value['target']['link']['url'], 'mobilUrl'=>$value['target']['link']['url'] ); } echo json_encode(array( 'success'=>true, 'title'=>'知乎热榜', 'update_time'=>date('y-m-d H:i:s',time()), 'data'=>$data, 'text' => [ 'copyright' => '苏晓晴 2022.10.23'] ) ); } //微博热搜榜解析实例 function weibo(){ $json = curl('https://weibo.com/ajax/side/hotSearch'); $json_data = json_decode($json, true); $data = []; //循环 foreach($json_data['data']['realtime'] as $key => $value){ $data[$key] = array( 'index'=>$key + 1, 'title'=>$value['note'], 'hot'=>$value['num'], 'url'=>'https://s.weibo.com/weibo?q='.$value['word_scheme'].'&t=31&band_rank=12&Refer=top', 'mobilUrl'=>'https://s.weibo.com/weibo?q='.$value['word_scheme'].'&t=31&band_rank=12&Refer=top' ); } echo json_encode(array( 'success'=>true, 'title'=>'微博热搜', 'update_time'=>date('y-m-d H:i:s',time()), 'data'=>$data, 'text' => [ 'copyright' => '苏晓晴 2022.10.23'] ) ); } //百度热搜榜解析实例 function baidu(){ $json = curl('https://top.baidu.com/board?tab=realtime&sa=fyb_realtime_31065'); preg_match('/<!--s-data:(.*?)-->/', $json, $json_data); $json_data = json_decode($json_data[1], true); //循环 foreach($json_data['data']['cards'] as $key => $value){ foreach($value['content'] as $keys => $projson){ $data[$keys] = array( 'index'=>$keys + 1, 'title'=>$projson['word'], 'pic'=>$projson['img'], 'hot'=>$projson['hotScore'], 'desc'=>$projson['desc'], 'url'=>$projson['url'], 'mobilUrl'=>$projson['appUrl'] ); } } echo json_encode(array( 'success'=>true, 'title'=>'百度热搜', 'update_time'=>date('y-m-d H:i:s',time()), 'data'=>$data, 'text' => [ 'copyright' => '苏晓晴 2022.10.23'] ) ); } //解析需要的参数 请勿乱动! function curl($url, $headers = []){ $header = ['User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36']; $con = curl_init((string)$url); curl_setopt($con, CURLOPT_HEADER, false); curl_setopt($con, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($con, CURLOPT_RETURNTRANSFER, true); if (!empty($headers)) { curl_setopt($con, CURLOPT_HTTPHEADER, $headers); } else { curl_setopt($con, CURLOPT_HTTPHEADER, $header); } curl_setopt($con, CURLOPT_TIMEOUT, 5000); $result = curl_exec($con); return $result; } ?>