Home  >  Article  >  php教程  >  PHP点赞狂魔功能

PHP点赞狂魔功能

PHP中文网
PHP中文网Original
2016-05-26 08:19:041597browse

作为开源中国点赞狂魔,必须有特殊的点赞技巧:

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

配合定时任务效果更佳

<?php
//点赞狂魔
class LikeDemon{
 public function index(){
 $this->login_osc(); //登录
}
//登录
 private function login_osc(){
 $post = array(&#39;email&#39; => &#39;你的邮箱账号&#39;,&#39;pwd&#39; => &#39;加密后的密码&#39;,&#39;save_login&#39; => &#39;1&#39;);
 $curl = curl_init(); //初始化curl模块
 curl_setopt($curl,CURLOPT_URL,&#39;https://www.oschina.net/action/user/hash_login&#39;); //登录提交的地址
 curl_setopt($curl,CURLOPT_HEADER,0); //是否显示头信息
curl_setopt($curl,CURLOPT_RETURNTRANSFER,0);
 curl_setopt($curl,CURLOPT_COOKIEJAR,&#39;./cookie.txt&#39;); //设置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,&#39;http://www.oschina.net/&#39;);
curl_setopt($curl,CURLOPT_HEADER,0);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
 curl_setopt($curl,CURLOPT_COOKIEFILE,&#39;./cookie.txt&#39;); //读取cookie
 $html = curl_exec($curl); //执行cURL抓取页面内容
//得到第一个动弹数据
 preg_match(&#39;/<span class=&#39;body&#39; id="(w+)">[sS]*?<!--添加点赞功能 END-->/&#39;,$html,$data);
//user_code
 $user_code = &#39;你的user_code&#39;;
 //logid & id
 $id = intval($data[1]);
 $logid = intval($data[1]);
//ownerOfLog
preg_match(&#39;/href="http://my.oschina.net/(.*?)"/&#39;,$data[0],$user_url);
curl_setopt($curl,CURLOPT_URL,&#39;http://my.oschina.net/&#39;.$user_url[1]);
 $user_html = curl_exec($curl); //执行cURL抓取页面内容
 preg_match(&#39;/<input type=&#39;hidden&#39; name=&#39;user&#39; value=&#39;(w+)&#39;/>/&#39;,$user_html,$ownerOfLog);
 $ownerOfLog = intval($ownerOfLog[1]);
//current_love_count
 preg_match(&#39;/id="TopTweets_love_(w+)_hidden"value="(w+)">/&#39;,$data[0],$current_love_count);
 $current_love_count = intval(trim($current_love_count[2]));
 $clickCount = intval(0);
 $arr = array(&#39;user_code&#39; => $user_code,&#39;logid&#39; => $logid,&#39;current_love_count&#39; => $current_love_count,&#39;id&#39; => $id,&#39;clickCount&#39; => $clickCount,&#39;ownerOfLog&#39; => $ownerOfLog);
 $user_id = file_get_contents(&#39;./user_id.txt&#39;); //本地用户ID
 $user_id != $ownerOfLog ? $this->click($arr) : &#39;&#39;; //如果本地的用户ID,不等于网页最新的用户ID,就执行点赞
curl_close($curl);
}
 public function click($arr){
 $curl = curl_init(); //初始化curl模块
 curl_setopt($curl,CURLOPT_URL,&#39;http://www.oschina.net/action/tweet/makeAsLove&#39;); //登录提交的地址
curl_setopt($curl,CURLOPT_HEADER,0);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
 curl_setopt($curl,CURLOPT_COOKIEFILE,&#39;./cookie.txt&#39;); //读取cookie
 curl_setopt($curl,CURLOPT_POST,1); //post方式提交
 curl_setopt($curl,CURLOPT_POSTFIELDS,http_build_query($arr)); //要提交的信息
 curl_exec($curl); //执行cURL
//存储用户ID
 $handle = fopen(&#39;./user_id.txt&#39;,"w");
fwrite($handle,$arr[&#39;ownerOfLog&#39;]);
fclose($handle);
curl_close($curl);
}
}
$LikeDemon = new LikeDemon();
$LikeDemon->index();
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn