百度热榜API源码
百度热点api前端效果
<?php
// 百度热点 指数
function baiduredian()
{
$_resHtml = str_replace(["\n", "\r", " "], '', vvhanCurl('https://top.baidu.com/board?tab=realtime', null));
preg_match('/<!--s-data:(.*?)-->/', $_resHtml, $_resHtmlArr);
$jsonRes = json_decode($_resHtmlArr[1], true);
return $jsonRes;
$tempArr = [];
foreach ($jsonRes['data']['cards'] as $v) {
foreach ($v['content'] as $k => $_v) {
array_push($tempArr, [
'index' => $k + 1,
'title' => $_v['word'],
'desc' => $_v['desc'],
'pic' => $_v['img'],
'url' => $_v['url'],
'hot' => $_v['hotScore'] . 'W个内容',
'mobilUrl' => $_v['appUrl']
]);
}
}
return [
'success' => true,
'title' => '百度热点',
'subtitle' => '指数',
'update_time' => date('Y-m-d h:i:s', time()),
'data' => $tempArr
];
}
?>
知乎热榜API源码
<?php
// 知乎热榜 热度
function zhihuHot()
{
$_resHtml = str_replace(["\n", "\r", " "], '', vvhanCurl('https://www.zhihu.com/hot', ['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'], 'https://www.zhihu.com'));
preg_match('/<scriptid=\"js-initialData\"type=\"text\/json\">(.*?)<\/script>/', $_resHtml, $_resHtmlArr);
$jsonRes = json_decode($_resHtmlArr[1], true);
$tempArr = [];
foreach ($jsonRes['initialState']['topstory']['hotList'] as $k => $v) {
array_push($tempArr, [
'index' => $k + 1,
'title' => $v['target']['titleArea']['text'],
'desc' => $v['target']['excerptArea']['text'],
'pic' => $v['target']['imageArea']['url'],
'hot' => $v['target']['metricsArea']['text'],
'url' => $v['target']['link']['url'],
'mobilUrl' => $v['target']['link']['url']
]);
}
return [
'success' => true,
'title' => '知乎热榜',
'subtitle' => '热度',
'update_time' => date('Y-m-d h:i:s', time()),
'data' => $tempArr
];
}
?>
未经允许不得转载:
作者: 路羽, 转载或复制请以 超链接形式 并注明出处 路羽博客。
原文地址: 《PHP-知乎热榜API源码、百度热点API源码》 发布于2023-2-5
新人报到学习一下