斗鱼熊猫战旗三大平台直播状态获取
嘛,其实也就是一大堆正则而已。。。。
直接上代码吧
<?php // ini_set('display_errors',1); //错误信息 // ini_set('display_startup_errors',1); //php启动错误信息 function replace_unicode_escape_sequence($match) { return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE'); } function unicodeDecode($data){ $rs=preg_replace_callback('/\\\\u([0-9a-f]{4})/i', 'replace_unicode_escape_sequence', $data); return $rs; } include("../config_mysqli.php"); $q=$mysqli->prepare("SELECT id,name,timestamp,title,status,avatar,type FROM douyu ORDER BY ord"); $uptime=time(); $q->bind_result($id,$name,$timestamp,$title,$status,$avatar,$type); $q->execute(); $table_change=array('\\'=>''); $up=Array(); while ($q->fetch()){ if ($type=="panda"){ if ($timestamp<$uptime-300){ $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/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36 '; $header[]='Host: www.panda.tv'; $header[]='referer: https://www.panda.tv/'; $header[]='Connection: Keep-Alive '; $header[]='authority: www.panda.tv '; curl_setopt($ch,CURLOPT_HTTPHEADER,$header); curl_setopt($ch,CURLOPT_URL,"https://www.panda.tv/".$id); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); $output=curl_exec($ch); curl_close($ch); // echo $output; $preg1="/room_key\"\:\".{32}\"\,\"status\"\:\"(\d)/"; preg_match_all($preg1,$output,$m); $s=$m[1][0]; $preg2="/hostinfo\'\:\s\{\"rid\"\:\d{1,10}\,\"name\"\:\".{1,50}\"\,\"avatar\"\:\"(.{1,200})\"\,\"bamboos/"; preg_match_all($preg2,$output,$m); $a=strtr($m[1][0],$table_change); $preg3="/roominfo\'\:\s\{\"id\"\:\"\d{1,10}\"\,\"name\"\:\"(.{1,200})\"\,\"bulletin/"; preg_match_all($preg3,$output,$m); $t=unicodeDecode($m[1][0]); if ($s=="2"){ echo "<div class='douyu_item'><div class='douyu_img'><img src='".$a."' /></div><div class='douyu_name'>".$name."</div><div class='douyu_title'><a href='https://www.panda.tv/".$id."'>".$t."</a></div></div>"; } array_push($up,Array($uptime,$t,$s,$a,$id)); }elseif ($status=="2"){ echo "<div class='douyu_item'><div class='douyu_img'><img src='".$avatar."' /></div><div class='douyu_name'>".$name."</div><div class='douyu_title'><a href='https://www.panda.tv/".$id."'>".$title."</a></div></div>"; } }elseif ($type=="douyu"){ if ($timestamp<$uptime-300){ $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: www.douyu.com'; $header[]='Referer: http://www.douyu.com'; $header[]='Connection: Keep-Alive '; curl_setopt($ch,CURLOPT_HTTPHEADER,$header); curl_setopt($ch,CURLOPT_URL,"https://www.douyu.com/".$id); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); $output=curl_exec($ch); curl_close($ch); //echo $output; $preg1="/ROOM\.show\_status\s\=\s(\d)/"; preg_match_all($preg1,$output,$m); $s=$m[1][0]; $preg2="/ROOM\.owner\_avatar\s\=\s\"(.{1,200}\.jpg)/"; preg_match_all($preg2,$output,$m); $a=strtr($m[1][0],$table_change); $preg3="/\<h\d class\=\"Title-headlineH2\"\>(.{1,200})\<\/h\d\>/"; preg_match_all($preg3,$output,$m); $t=$m[1][0]; if ($s=="1"){ echo "<div class='douyu_item'><div class='douyu_img'><img src='".$a."' /></div><div class='douyu_name'>".$name."</div><div class='douyu_title'><a href='https://www.douyu.com/".$id."'>".$t."</a></div></div>"; } array_push($up,Array($uptime,$t,$s,$a,$id)); }elseif ($status=="1"){ echo "<div class='douyu_item'><div class='douyu_img'><img src='".$avatar."' /></div><div class='douyu_name'>".$name."</div><div class='douyu_title'><a href='https://www.douyu.com/".$id."'>".$title."</a></div></div>"; } }elseif ($type=="zhanqi"){ if ($timestamp<$uptime-300){ $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: www.zhanqi.tv'; $header[]='Referer: http://www.zhanqi.tv'; $header[]='Connection: Keep-Alive '; curl_setopt($ch,CURLOPT_HTTPHEADER,$header); curl_setopt($ch,CURLOPT_URL,"https://www.zhanqi.tv/".$id); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); $output=curl_exec($ch); curl_close($ch); //echo $output; $preg1="/window\.oPageConfig\.oRoom.{1,200}avatar\"\:\"(.{1,200}jpg)\".{1,200}title\"\:\"\s{0,15}(.{1,200})\",\"gameId.{1,200}status\"\:\"(\d)/"; preg_match_all($preg1,$output,$m); // print_r($m); $t=$m[2][0]; $s=$m[3][0]; $a=$m[1][0]; if ($s=="4"){ echo "<div class='douyu_item'><div class='douyu_img'><img src='".$a."' /></div><div class='douyu_name'>".$name."</div><div class='douyu_title'><a href='https://www.zhanqi.tv/".$id."'>".$t."</a></div></div>"; } array_push($up,Array($uptime,$t,$s,$a,$id)); }elseif ($type=="4"){ echo "<div class='douyu_item'><div class='douyu_img'><img src='".$avatar."' /></div><div class='douyu_name'>".$name."</div><div class='douyu_title'><a href='https://www.zhanqi.tv/".$id."'>".$title."</a></div></div>"; } } } $q->close(); $q2=$mysqli->prepare("UPDATE douyu SET timestamp=?,title=?,status=?,avatar=? WHERE id=?"); foreach ($up as $a){ // print_r($a); $q2->bind_param("isiss",$a[0],$a[1],$a[2],$a[3],$a[4]); $q2->execute(); } $q2->close(); ?>
其中战旗的头像似乎不允许跨域调用,后面还得写个假的referer
2019
01 17
上一篇
Older
下一篇
Newer
评论
2
点击
3717
贴吧观光团~
求大佬把http://zyho.me/yuzusoft/ 开源