随机抓取新浪微博指定用户的小视频地址,标题,你问我用途,暂不明,没用上,分享一下。
<?php $ids = [3881380517,2286908003,1752825395,2656274875,3266943013,1663072851]; $key = array_rand($ids); $id = $ids[$key]; $geturl = 'https://weibo.com/ajax/statuses/mymblog?uid=' . $id . '&page=1&feature=0'; $result = get_curl( $geturl ,0 ,'https://weibo.com/u/' . $id . '?lpage=profileRecom' ,'XSRF-TOKEN=HBrPLdHRfCgCoNaAJDVx6R5B; SUB=_2AkMTNC0Cf8NxqwFRmfgWy2PqZIxyyw3EieKlaNzZJRMxHRl-yT9vqnQCtRB6OLQD7VqVLExFvLzJRwLjpHYx1gN3b66X;' ,0 ,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36' ,0 ,0 ); $array = json_decode($result); $array->data->list[1]->page_info->object_type; //print_r($array->data->list[1]); if (!empty($array->data->list[1]->page_info->object_type) && $array->data->list[1]->page_info->object_type == 'video') { //print_r($array->data->list[1]->page_info->media_info); echo $array->data->list[1]->page_info->media_info->next_title; echo PHP_EOL; echo $array->data->list[1]->page_info->media_info->stream_url; } /*preg_match_all('/\"mp4_720p_mp4\":\"(.*?)\"/', $result, $matches); print_r($matches);*/ /*if (!empty($matches[1])) { $key = array_rand($matches[1]); $url = $matches[1][$key]; file_put_contents(__DIR__ . '/下载.mp4', get_curl($url)); }*/ function get_curl($url,$post=0,$referer=1,$cookie=0,$header=0,$ua=0,$nobaody=0,$addheader=0) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $httpheader[] = "Accept: application/json"; //$httpheader[] = "Accept-Encoding: gzip,deflate,sdch"; $httpheader[] = "Accept-Language: zh-CN,zh;q=0.8"; $httpheader[] = "Connection: close"; if($addheader){ $httpheader = array_merge($httpheader, $addheader); } curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader); if($post){ curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); } if($header){ curl_setopt($ch, CURLOPT_HEADER, TRUE); } if($cookie){ curl_setopt($ch, CURLOPT_COOKIE, $cookie); } if($referer){ if($referer==1){ curl_setopt($ch, CURLOPT_REFERER, 'http://m.qzone.com/infocenter?g_f='); }else{ curl_setopt($ch, CURLOPT_REFERER, $referer); } } if($ua){ curl_setopt($ch, CURLOPT_USERAGENT,$ua); }else{ curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Linux; U; Android 4.4.1; zh-cn) AppleWebKit/533.1 (KHTML, like Gecko)Version/4.0 MQQBrowser/5.5 Mobile Safari/533.1'); } if($nobaody){ curl_setopt($ch, CURLOPT_NOBODY,1); } curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_ENCODING, "gzip"); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); $ret = curl_exec($ch); curl_close($ch); //$ret=mb_convert_encoding($ret, "UTF-8", "UTF-8"); return $ret; }