2020.12.18最新的B站动态抓取
B站昨天还是前天左右突然更换了feeds的API,所以重新写了一个抓取
function bili($mycookie,$hist){ $ch=curl_init(); $header=Array(); $header[]='Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, text/html, * /* '; $header[]='Accept-Language: zh-cn '; $header[]='User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727) '; $header[]='Host: api.vc.bilibili.com'; $header[]='Connection: Keep-Alive '; $header[]='Cookie: '.$mycookie; curl_setopt($ch,CURLOPT_HTTPHEADER,$header); if ($hist==""){ curl_setopt($ch,CURLOPT_URL,"https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_new?uid=你的ID&type_list=8,512,4097,4098,4099,4100,4101"); }else{ curl_setopt($ch,CURLOPT_URL,"https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_history?uid=你的ID&type_list=8,512,4097,4098,4099,4100,4101&offset_dynamic_id=".$hist); } curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); $output=curl_exec($ch); // curl_close($ch); return $output; /* if (!strpos($output,'{"code":-101}')){ echo $mycookie." --------- "; return true; }else{ return false; }*/ } /*function dg($start,$now,$str){ global $cookies,$dump,$max,$found; if ($now<$dump){ for ($i=$start+1;$i<$max;$i++){ dg($i,$now+1,$str.$cookies[$i].";"); } }else{ // echo $str."<br />"; if (bili($str)){ $found=true; } } } $found=false; $dump=0; $dumps=Array(0); $max=count($cookies); while (!$found && $dump<$max){ dg(-1,0,""); $dump++; }*/ echo "bili_arr=["; $i=0; $hist=""; for ($page=1;$page<5;$page++){ $output=bili($config['bilibilicookie'],$hist); // echo $output; // $output=substr($output,strpos($output,"(")+1,-1); // echo $output; //echo substr($output,strpos($output,"(")+1,-2); //echo substr($output,strpos($output,"(")+1,-2); $arr=json_decode($output,true); // print_r($arr['data']['cards']); $table_change=array('\\'=>'\\\\','\''=>'\\\''); foreach($arr['data']['cards'] as $thing){ // print_r($card); if ($thing['desc']['type']==8){ $card=json_decode($thing['card'],true); echo ($i>0?",":"")."['".strtr($thing['desc']['bvid'],$table_change)."','".strtr($card['title'],$table_change)."','".strtr($card['owner']['name'],$table_change)."','".strtr($card['pic'],$table_change)."']"; $i=1; $hist=$thing['desc']['dynamic_id_str']; }else{ $card=json_decode($thing['card'],true); // print_r($card); // print_r($thing); echo ($i>0?",":"")."['".strtr($card['episode_id'],$table_change)."','".strtr($card['new_desc'],$table_change)."','".strtr($card['apiSeasonInfo']['title'],$table_change)."','".strtr($card['cover'],$table_change)."']"; $i=1; $hist=$thing['desc']['dynamic_id_str']; } } } echo "];bili_go();";
2020
12 18
上一篇
Older
下一篇
Newer
评论
0
点击
1265