优酷来疯直播群发信息,如何加入模拟登录交流群?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1111个文字,预计阅读时间需要5分钟。
python模拟登录来疯直播平台,获取当前直播间的房间ID并群发信息import requests
def login_lai_feng(): # 登录URL login_url=http://www.laifeng.com/login # 登录所需数据,这里用示例数据代替 login_data={ 'username': 'your_username', 'password': 'your_password' } # 发送登录请求 response=requests.post(login_url, data=login_data) # 检查登录是否成功 if response.status_code==200: return response.json() else: return None
def get_live_room_id(): # 获取直播房间ID的URL room_id_url=http://www.laifeng.com/get_room_id # 发送请求获取房间ID response=requests.get(room_id_url) # 检查请求是否成功 if response.status_code==200: return response.json().get('room_id') else: return None
def send_group_message(room_id): # 群发消息的URL message_url=fhttp://www.laifeng.com/send_message?room_id={room_id} # 消息内容 message_content=Hello, this is a test message! # 发送消息 response=requests.post(message_url, data={'message': message_content}) # 检查消息是否发送成功 if response.status_code==200: print(Message sent successfully.) else: print(Failed to send message.)
执行登录user_info=login_lai_feng()if user_info: # 获取房间ID room_id=get_live_room_id() if room_id: # 群发信息 send_group_message(room_id) else: print(Failed to get room ID.)else: print(Failed to login.)
来疯直播间模拟登录,抓取正在直播的房间ID并群发信息,来疯首页www.laifeng.com/,代码注释每个方法前都写的很清楚,我想这么几行代码没办要每行都加注释吧?请大家注意口德最底行有DEMO下载地址
1.[代码][PHP]代码
<?php //使用时必须先配置 //$cookiefile(COOKIE 存放路径) //$user(用户名,优酷土豆来疯都行) //$pass(密码,优酷土豆来疯都行); class laifeng { //cookie存放路径 private $cookiefile = "cookie.txt"; //房间号 private $id; //用户名 private $user='1234@qq.com'; //密码 private $pass=12345678; //初始化ID public function __construct($idd=null){ $this->id=$idd; } //模拟登录获取yktk public function getkey() { $user=urldecode($this->user); $pass=urldecode(md5($this->pass)); $url = "www.laifeng.com/login/"; $data = "userName=".$user."&password=".$pass."&forever=1&returnurl=www.laifeng.com/login/"); curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"); $info = curl_exec($ch); curl_close($ch); $y = json_decode($info, true); $yktk = $y['response']; return $yktk; } //获取cookie private function login(){ $yktk=$this->getkey(); if($yktk['code']!=0){ echo $yktk['msg']; exit(); }else{ $url=$yktk['data']; $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_HEADER,1); curl_setopt($ch,CURLOPT_COOKIEFILE,$this->cookiefile); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_REFERER,"www.laifeng.com/".$this->id); curl_setopt($ch,CURLOPT_COOKIEJAR,$this->cookiefile); curl_exec($ch); curl_close($ch); echo("<script>location.reload();</script>"); return $yktk['msg']; //echo $y[1]; } } //输出页面 public function curl(){ $this->login(); $url="www.laifeng.com/".$this->id; $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_COOKIEFILE,$this->cookiefile); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_REFERER,"www.laifeng.com/".$this->id); curl_setopt($ch,CURLOPT_COOKIEJAR,$this->cookiefile); $info=curl_exec($ch); $info=str_replace('room/js','static.youku.com/ddshow/8125f00c/room/js',$info); curl_close($ch); return $info; } //获取用户名 public function top(){ $url="www.laifeng.com"; $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_HEADER,1); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_REFERER,"www.laifeng.com/"); curl_setopt($ch,CURLOPT_COOKIEFILE,$this->cookiefile); $m=curl_exec($ch); curl_close($ch); $mate="@<a class=\"user-name-link\" href=\"/my/profile/init\" target=\"_blank\" title=\"(.*)\">@iUs"; preg_match_all($mate,$m,$arr); if(@$arr[1][0]){ echo $arr[1][0]; }else{ echo("<script>alert('登录超时,正在尝试自动登录.....');</script>"); echo $this->login(); } } //发送信息模板 public function msg($msg,$url){ //$url="www.laifeng.com/room/7437/chat/save"; $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_REFERER,"www.laifeng.com/".$this->id); curl_setopt($ch,CURLOPT_POSTFIELDS,$msg); curl_setopt($ch,CURLOPT_COOKIEFILE,$this->cookiefile); $info=curl_exec($ch); curl_close($ch); $arr=json_decode($info,true); if($arr['response']['code']==-2){ echo("<script>alert('登录超时,正在尝试自动登录.....');</script>"); echo $this->login(); }else{ echo $arr['response']['msg']; } } //发送文字 参数为发送内容 public function msgtxt($data){ $msg="single=0&content=".urlencode($data)."&anchorId=0&roomId=".$this->id; $url="www.laifeng.com/room/".$this->id."/chat/save"; return $this->msg($msg,$url); } //送花 参数为数量 public function flower($data=1){ $msg="roomId=".$this->id."&quantity=".$data; $url="www.laifeng.com/room/".$this->id."/star/send"; return $this->msg($msg,$url); } //抓取正在直播的ID }//laifeng class class exe{ //抓取房间ID public function anchor($pageid=1){ $page=file_get_contents("www.laifeng.com/anchor/search?pageNo=".$pageid); //$count=file_get_contents("www.laifeng.com/anchor/search"); $mage="@<p class=\"name\">(.*)<a href=\"/(.*)\" title=\"(.*)\" target=\"_blank\">(.*)</a>@iUs"; $match="@//总页数(.*)totalNum:(.*),(.*)//当前页数@iUs"; preg_match_all($mage,$page,$arr); preg_match_all($match,$page,$pagecount); $page=array(); $page['count']=$pagecount[2][0]; $page['data']=$arr[2]; return $page; } //抓取房间总页数 public function pagecount(){ $page=file_get_contents("www.laifeng.com/anchor/search"); $match="@//总页数(.*)totalNum:(.*),(.*)//当前页数@iUs"; preg_match_all($match,$page,$arr); echo $arr[2][0]; } } //$exe=new exe(); //$exe->pagecount(); //$arr=$exe->anchor(1); //foreach($arr as $k=>$v){ // $lai=new laifeng($v); // echo"房间ID:".$v." "; // echo $lai->msgtxt('嗨'); // echo"<br />"; //} //echo $lai->msgtxt("这是一段测试文字1234"); //for($i=7437;$i<=7439;$i++){ // $lai=new laifeng($i); // echo $lai->msgtxt("1111"); //} //$lai->flower(1); //echo $lai->curl(); ?>
2.[图片] QQ图片20150616184431.jpg
本文共计1111个文字,预计阅读时间需要5分钟。
python模拟登录来疯直播平台,获取当前直播间的房间ID并群发信息import requests
def login_lai_feng(): # 登录URL login_url=http://www.laifeng.com/login # 登录所需数据,这里用示例数据代替 login_data={ 'username': 'your_username', 'password': 'your_password' } # 发送登录请求 response=requests.post(login_url, data=login_data) # 检查登录是否成功 if response.status_code==200: return response.json() else: return None
def get_live_room_id(): # 获取直播房间ID的URL room_id_url=http://www.laifeng.com/get_room_id # 发送请求获取房间ID response=requests.get(room_id_url) # 检查请求是否成功 if response.status_code==200: return response.json().get('room_id') else: return None
def send_group_message(room_id): # 群发消息的URL message_url=fhttp://www.laifeng.com/send_message?room_id={room_id} # 消息内容 message_content=Hello, this is a test message! # 发送消息 response=requests.post(message_url, data={'message': message_content}) # 检查消息是否发送成功 if response.status_code==200: print(Message sent successfully.) else: print(Failed to send message.)
执行登录user_info=login_lai_feng()if user_info: # 获取房间ID room_id=get_live_room_id() if room_id: # 群发信息 send_group_message(room_id) else: print(Failed to get room ID.)else: print(Failed to login.)
来疯直播间模拟登录,抓取正在直播的房间ID并群发信息,来疯首页www.laifeng.com/,代码注释每个方法前都写的很清楚,我想这么几行代码没办要每行都加注释吧?请大家注意口德最底行有DEMO下载地址
1.[代码][PHP]代码
<?php //使用时必须先配置 //$cookiefile(COOKIE 存放路径) //$user(用户名,优酷土豆来疯都行) //$pass(密码,优酷土豆来疯都行); class laifeng { //cookie存放路径 private $cookiefile = "cookie.txt"; //房间号 private $id; //用户名 private $user='1234@qq.com'; //密码 private $pass=12345678; //初始化ID public function __construct($idd=null){ $this->id=$idd; } //模拟登录获取yktk public function getkey() { $user=urldecode($this->user); $pass=urldecode(md5($this->pass)); $url = "www.laifeng.com/login/"; $data = "userName=".$user."&password=".$pass."&forever=1&returnurl=www.laifeng.com/login/"); curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"); $info = curl_exec($ch); curl_close($ch); $y = json_decode($info, true); $yktk = $y['response']; return $yktk; } //获取cookie private function login(){ $yktk=$this->getkey(); if($yktk['code']!=0){ echo $yktk['msg']; exit(); }else{ $url=$yktk['data']; $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_HEADER,1); curl_setopt($ch,CURLOPT_COOKIEFILE,$this->cookiefile); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_REFERER,"www.laifeng.com/".$this->id); curl_setopt($ch,CURLOPT_COOKIEJAR,$this->cookiefile); curl_exec($ch); curl_close($ch); echo("<script>location.reload();</script>"); return $yktk['msg']; //echo $y[1]; } } //输出页面 public function curl(){ $this->login(); $url="www.laifeng.com/".$this->id; $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_COOKIEFILE,$this->cookiefile); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_REFERER,"www.laifeng.com/".$this->id); curl_setopt($ch,CURLOPT_COOKIEJAR,$this->cookiefile); $info=curl_exec($ch); $info=str_replace('room/js','static.youku.com/ddshow/8125f00c/room/js',$info); curl_close($ch); return $info; } //获取用户名 public function top(){ $url="www.laifeng.com"; $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_HEADER,1); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_REFERER,"www.laifeng.com/"); curl_setopt($ch,CURLOPT_COOKIEFILE,$this->cookiefile); $m=curl_exec($ch); curl_close($ch); $mate="@<a class=\"user-name-link\" href=\"/my/profile/init\" target=\"_blank\" title=\"(.*)\">@iUs"; preg_match_all($mate,$m,$arr); if(@$arr[1][0]){ echo $arr[1][0]; }else{ echo("<script>alert('登录超时,正在尝试自动登录.....');</script>"); echo $this->login(); } } //发送信息模板 public function msg($msg,$url){ //$url="www.laifeng.com/room/7437/chat/save"; $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_REFERER,"www.laifeng.com/".$this->id); curl_setopt($ch,CURLOPT_POSTFIELDS,$msg); curl_setopt($ch,CURLOPT_COOKIEFILE,$this->cookiefile); $info=curl_exec($ch); curl_close($ch); $arr=json_decode($info,true); if($arr['response']['code']==-2){ echo("<script>alert('登录超时,正在尝试自动登录.....');</script>"); echo $this->login(); }else{ echo $arr['response']['msg']; } } //发送文字 参数为发送内容 public function msgtxt($data){ $msg="single=0&content=".urlencode($data)."&anchorId=0&roomId=".$this->id; $url="www.laifeng.com/room/".$this->id."/chat/save"; return $this->msg($msg,$url); } //送花 参数为数量 public function flower($data=1){ $msg="roomId=".$this->id."&quantity=".$data; $url="www.laifeng.com/room/".$this->id."/star/send"; return $this->msg($msg,$url); } //抓取正在直播的ID }//laifeng class class exe{ //抓取房间ID public function anchor($pageid=1){ $page=file_get_contents("www.laifeng.com/anchor/search?pageNo=".$pageid); //$count=file_get_contents("www.laifeng.com/anchor/search"); $mage="@<p class=\"name\">(.*)<a href=\"/(.*)\" title=\"(.*)\" target=\"_blank\">(.*)</a>@iUs"; $match="@//总页数(.*)totalNum:(.*),(.*)//当前页数@iUs"; preg_match_all($mage,$page,$arr); preg_match_all($match,$page,$pagecount); $page=array(); $page['count']=$pagecount[2][0]; $page['data']=$arr[2]; return $page; } //抓取房间总页数 public function pagecount(){ $page=file_get_contents("www.laifeng.com/anchor/search"); $match="@//总页数(.*)totalNum:(.*),(.*)//当前页数@iUs"; preg_match_all($match,$page,$arr); echo $arr[2][0]; } } //$exe=new exe(); //$exe->pagecount(); //$arr=$exe->anchor(1); //foreach($arr as $k=>$v){ // $lai=new laifeng($v); // echo"房间ID:".$v." "; // echo $lai->msgtxt('嗨'); // echo"<br />"; //} //echo $lai->msgtxt("这是一段测试文字1234"); //for($i=7437;$i<=7439;$i++){ // $lai=new laifeng($i); // echo $lai->msgtxt("1111"); //} //$lai->flower(1); //echo $lai->curl(); ?>

