代码语言:javascript复制
<?php
class Curl
{
//微博热点监控
public function Get_url_wb($url, $header)
{
$wburl = "https://s.weibo.com/weibo?q=";
// 1. 初始化 curl
$ch = curl_init();
// 设置URL和相应的选项
curl_setopt($ch, CURLOPT_URL, $url);//设置目标url
curl_setopt($ch, CURLOPT_HEADER, false);
//设置header
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_HEADER, 0);//返回response头部信息
//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//规避SSL验证
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//跳过HOST验证
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
//运行curl
$data = curl_exec($ch);
curl_close($ch);
preg_match_all('/top" target="_blank">(.*?)</a>/U', $data, $Hot_search);//热搜名
preg_match_all('/<span>(.*?)</span>/U', $data, $Hotspot);//热度
preg_match_all('/href="/weibo?q=(.*?)Refer=top/U', $data, $Hoturl);//热度url
for ($i = 0; $i < count($Hoturl[1]); $i ) {
$Hoturl[1][$i] = $wburl . $Hoturl[1][$i];
}
$arr = ["Hot_search" => $Hot_search[1], "Hotspot" => $Hotspot[1], "Hoturl" => $Hoturl[1]];
return json_encode($arr, 448);
}
}
$a = new Curl();
$header = array();
echo $a->Get_url_wb("https://s.weibo.com/top/summary", $header);
版权属于:尹深
本文链接:https://cloud.tencent.com/developer/article/1795096
转载时须注明出处及本声明
(本站部分资源来自互联网收集整理!如有侵权请联系站长删除!!!)