> php教程 > PHP源码 > 본문

PHP点赞狂魔功能

PHP中文网
풀어 주다: 2016-05-26 08:19:04
원래의
1566명이 탐색했습니다.

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

账号登录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();
로그인 후 복사
관련 라벨:
php
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!