欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

PHP点赞狂魔功能

程序员文章站 2022-04-17 11:08:24
...
作为开源中国点赞狂魔,必须有特殊的点赞技巧:

账号登录OSC,并获取首页右侧第一个动弹的属性后点击"赞",如果第一个用户被点击过则不会重复点击

配合定时任务效果更佳
<?php
//点赞狂魔
class LikeDemon{
 public function index(){
 $this->login_osc(); //登录
}
//登录
 private function login_osc(){
 $post = array('email' => '你的邮箱账号','pwd' => '加密后的密码','save_login' => '1');
 $curl = curl_init(); //初始化curl模块
 curl_setopt($curl,CURLOPT_URL,'https://www.oschina.net/action/user/hash_login'); //登录提交的地址
 curl_setopt($curl,CURLOPT_HEADER,0); //是否显示头信息
curl_setopt($curl,CURLOPT_RETURNTRANSFER,0);
 curl_setopt($curl,CURLOPT_COOKIEJAR,'./cookie.txt'); //设置cookie信息保存在指定的文件中
 curl_setopt($curl,CURLOPT_POST,1); //post方式提交
 curl_setopt($curl,CURLOPT_POSTFIELDS,http_build_query($post)); //要提交的信息
 $res = curl_exec($curl); //执行cURL
 $res ? $this->get_data($curl) : curl_close($curl);
}
//获得数据
 private function get_data($curl){
curl_setopt($curl,CURLOPT_URL,'http://www.oschina.net/');
curl_setopt($curl,CURLOPT_HEADER,0);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
 curl_setopt($curl,CURLOPT_COOKIEFILE,'./cookie.txt'); //读取cookie
 $html = curl_exec($curl); //执行cURL抓取页面内容
//得到第一个动弹数据
 preg_match('/<span class='body' id="(w+)">[sS]*?<!--添加点赞功能 END-->/',$html,$data);
//user_code
 $user_code = '你的user_code';
 //logid & id
 $id = intval($data[1]);
 $logid = intval($data[1]);
//ownerOfLog
preg_match('/href="http://my.oschina.net/(.*?)"/',$data[0],$user_url);
curl_setopt($curl,CURLOPT_URL,'http://my.oschina.net/'.$user_url[1]);
 $user_html = curl_exec($curl); //执行cURL抓取页面内容
 preg_match('/<input type='hidden' name='user' value='(w+)'/>/',$user_html,$ownerOfLog);
 $ownerOfLog = intval($ownerOfLog[1]);
//current_love_count
 preg_match('/id="TopTweets_love_(w+)_hidden"value="(w+)">/',$data[0],$current_love_count);
 $current_love_count = intval(trim($current_love_count[2]));
 $clickCount = intval(0);
 $arr = array('user_code' => $user_code,'logid' => $logid,'current_love_count' => $current_love_count,'id' => $id,'clickCount' => $clickCount,'ownerOfLog' => $ownerOfLog);
 $user_id = file_get_contents('./user_id.txt'); //本地用户ID
 $user_id != $ownerOfLog ? $this->click($arr) : ''; //如果本地的用户ID,不等于网页最新的用户ID,就执行点赞
curl_close($curl);
}
 public function click($arr){
 $curl = curl_init(); //初始化curl模块
 curl_setopt($curl,CURLOPT_URL,'http://www.oschina.net/action/tweet/makeAsLove'); //登录提交的地址
curl_setopt($curl,CURLOPT_HEADER,0);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
 curl_setopt($curl,CURLOPT_COOKIEFILE,'./cookie.txt'); //读取cookie
 curl_setopt($curl,CURLOPT_POST,1); //post方式提交
 curl_setopt($curl,CURLOPT_POSTFIELDS,http_build_query($arr)); //要提交的信息
 curl_exec($curl); //执行cURL
//存储用户ID
 $handle = fopen('./user_id.txt',"w");
fwrite($handle,$arr['ownerOfLog']);
fclose($handle);
curl_close($curl);
}
}
$LikeDemon = new LikeDemon();
$LikeDemon->index();
相关标签: PHP