斗鱼直播状态获取模块
其实嘛也就是三个正则。。。
$preg1="/ROOM\.show\_status\s\=\s(\d)/"; $preg2="/ROOM\.owner\_avatar\s\=\s\"(.{1,200}\.jpg)/"; $preg3="/\<h2 class\=\"Title-headlineH2\"\>(.{1,200})\<\/h2\>/";
分别是直播状态(1开2关),头像和标题了。。。
然后干货如下:
<?php include("../config_mysqli.php"); $q=$mysqli->prepare("SELECT id,name,timestamp,title,status,avatar FROM douyu WHERE type='douyu' ORDER BY ord"); $uptime=time()-600; $q->bind_result($id,$name,$timestamp,$title,$status,$avatar); $q->execute(); $table_change=array('\\'=>''); $up=Array(); while ($q->fetch()){ if ($timestamp<$uptime){ $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="/\<h2 class\=\"Title-headlineH2\"\>(.{1,200})\<\/h2\>/"; preg_match_all($preg3,$output,$m); $t=$m[1][0]; if ($s=="1"){ echo "<a href='https://www.douyu.com/".$id."' class='douyu_item'><div class='douyu_img'><img src='".$a."' /></div><div class='douyu_name'>".$name."</div><div class='douyu_title'>".$t."</div></a>"; } array_push($up,Array($uptime,$t,$s,$a,$id)); }else{ if ($status=="1"){ echo "<a href='https://www.douyu.com/".$id."' class='douyu_item'><div class='douyu_img'><img src='".$avatar."' /></div><div class='douyu_name'>".$name."</div><div class='douyu_title'>".$title."</div></a>"; } } } $q->close(); $q2=$mysqli->prepare("UPDATE douyu SET timestamp=?,title=?,status=?,avatar=? WHERE id=?"); foreach ($up as $a){ $q2->bind_param("isisi",$a[0],$a[1],$a[2],$a[3],$a[4]); $q2->execute(); } $q2->close(); ?>
2018
11 29
上一篇
Older
下一篇
Newer
评论
0
点击
2778