• ----:)欢迎访问源码网(:----
    • 首页
    • 博客
    • 学院
    • 下载
    • 论坛
    • 影视
    • 发布源码
    • RSS
    • ITPig
    • 笑话网
    • 百家姓
    • 繁體中文

源码网 - 中国第一源码门户
选择镜像:网通镜像 - 电信主站
  • 首 页
  • 新闻动态
  • 网站运营
  • 网页制作
  • WEB开发
  • 编程开发
  • 图像媒体
  • 操作系统
  • 数据库
  • 服务器
热门搜索 优化 SEO 故事 cms IIS7 MySQL 个人 AdSense 主题推广 | 文章搜索: 高级搜索
会员登录/控制面版您的位置: 学院首页 >> WEB开发 >> PHP 开发 >> PHP精通 >> 详细内容
 

推荐文章

  • PHP 程序加速探索
  • 用封装类来合理的设计PHP项目--谈PHP项目中类的封装
 
 

热点文章

  • 30分钟学会用PHP写带数据库的简单通讯录
  • 结合AJAX进行PHP开发之入门
  • 最强的PHP字符串截取函数
  • 汉字编码问题
  • PHP向脚本提交POST数据
  • 中文字符集与字符编码的基础知识
  • PHP实现验证码一法
  • php模板smarty
  • php如何隐藏图片的真实地址
  • PHP 程序加速探索
  • php防盗链的方法
  • 用封装类来合理的设计PHP项目--谈PHP项目中类的封装
 
 

相关文章

  • PHP初级程序员面试题及答案
  • PHP使用zlib扩展实现页面GZIP压缩输出
  • 为什么PHP令人不爽(对于大型系统)
  • php中的stdClass
  • php中ADODB类使用
  • Linux/FreeBSD下用C语言开发PHP的so扩展模块例解
  • php取不到session的常见原因
  • 使用php的zlib压缩和解压缩swf文件
  • php 做服务器端程序
  • PHP5.2下function和class性能对比
  • PHP用mkdir()新建立目录无写的权限的问题
  • mysql的bigint类型与php的mysql_insert_id函数造成的b..
 
 

百度搜索

 
 

php自动post数据--百度贴吧灌水机器人代码实例

  • 阅览次数:
  • 文章来源:
  • 原文作者:
  • 整理日期: 2008-08-18
  • 发表评论
  • 字体大小:
  • 小
  • 中
  • 大

PHP:  

<?php
/**
  * baidu 贴吧自动回帖机
  * author: hetal
  * email : [email]huoqi29@163.com[/email]
  * qq    : 231073376
  * msn   : [email]hetao29@hotmail.com[/email]
  * web   : [url]http://www.haqoo.com[/url]
  *
  */
class Baidu_Post{
    var
$proxyPort;
    var
$proxyHost;
    var
$cookie;
    
//设置代理 ,ok
    
function setProxy($proxyHost,$proxyPort){
        
$this->proxyPort=$proxyPort;
        
$this->proxyHost=$proxyHost;
    }
    
//初始化baiduID ,ok
    
function init(){
        
$data = $this->_getUrl("/u/info_img/2008-08/18/logo.gif");
            
preg_match_all ("/Set-Cookie: (.+?)=(.+?);/", $data, $_matches,PREG_SET_ORDER);
            
$tmp=array();
            for(
$i=0;$i<count($_matches);$i++){
                    
$tmp[]=$_matches[$i][1]."=".$_matches[$i][2];
            }
            
$this->cookie=implode(';',$tmp);
    }
    
//登录
    
function login($user,$pass){
        
$cookie=$this->cookie;
        
$post_data ="tpl=&tpl_ok=&skip_ok=&aid=0&need_pay=&need_coin=0&pay_method=0&u=&next_target=&return_method=&more_param=&return_type=&username=$user&password=$pass&Submit=+%B5%C7%C2%BC+";
        
$post_data_le = strlen($post_data);
        if(!empty(
$this->proxyPort) and !empty($this->proxyHost)){
            
$post_url="http://passport.baidu.com/?login";
            
$post_port=$this->proxyPort;
            
$post_host=$this->proxyHost;
            
$connect="Proxy-Connection";
        }else{
            
$post_url="/?login";
            
$post_port=80;
            
$connect="Connection";
            
$post_host="passport.baidu.com";
        }
        
$data="POST $post_url HTTP/1.1\nAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\nReferer: [url]http://passport.baidu.com/?login[/url]\nAccept-Language: zh-cn\nContent-Type: application/x-www-form-urlencoded\nAccept-Encoding: gzip, deflate\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Alexa Toolbar)\nHost: passport.baidu.com\nContent-Length: $post_data_le\n$connect: Keep-Alive\nCache-Control: no-cache\nCookie: $cookie\n\n$post_data\n";
        
$sock = fsockopen($post_host,$post_port,$errno,$error,3);
        
fputs($sock,$data);
        while(
$rt[]=fgets($sock)){}
        
fclose($sock);
        
$rt=implode("",$rt);
        
$rt=str_replace("\n","",$rt);
        
$rt=str_replace("\t","",$rt);
        
preg_match_all ("/Set-Cookie: (.+?)=(.+?);/", $rt, $_matches,PREG_SET_ORDER);
        
$tmp=array();
        for(
$i=0;$i<count($_matches);$i++){
                
$tmp[]=$_matches[$i][1]."=".$_matches[$i][2];
        }
        
$this->cookie=$cookie.";".implode(';',$tmp);
        if(isset(
$tmp['BDUSS']) and !empty($tmp['BDUSS'])){
            return
0;
        }else{
            return
1;
        }
    }
    
//得到最热的500个贴吧
    
function getTop500($url="http://post.baidu.com/tb/firstindex/1.html"){
        
$content=$this->_getUrl($url);
        
$title=array();
        
//preg_match_all ("/\<a href=\"http\:\/\/post\.baidu\.com\/f(.+?)\"(.+?)\>(.+?)\<\/a\>/", $content, $_matches,PREG_SET_ORDER);
        
preg_match_all ("/\<a href=\"\/f(.+?)\"(.+?)\>(.+?)\<\/a\>/", $content, $_matches,PREG_SET_ORDER);
        foreach(
$_matches as $value){
            
$tmp=array();
            
$tmp['url']="http://post.baidu.com/f".$value[1];
            
$tmp['title']=$value[3];
            
$title[]=$tmp;
        }
        return
$title;
    
    }
    
//得到每个贴吧对应的第1页的贴子
    
function getTitle($tieba_url){
        
$content=$this->_getUrl($tieba_url);
        
//echo $content;
        
$title=array();
        
preg_match_all ("/\<a(.+?)href=\"\/f\?kz=(.+?)\"(.+?)\>(.+?)\<\/a\>/", $content, $_matches,PREG_SET_ORDER);
        
//print_r($_matches);
        
foreach($_matches as $value){
            
$tmp=array();
            
$tmp['url']="http://post.baidu.com/f?kz=".$value[2];
            
$tmp['title']=$value[4];
            
$title[]=$tmp;
        }
        return
$title;
    }
    
//回贴
    
function huitie($url,$title1,$title="",$content="",$logo="http://"){
        
$fileds=$this->_getTie($url);
        if(empty(
$fileds)){return -1;}
        
$tmp[]="ct=".$fileds['ct'];
        
$tmp[]="tn=".$fileds['tn'];
        
$tmp[]="word=".urlencode($fileds['word']);
        
$tmp[]="lm=".$fileds['lm'];
        
$tmp[]="z=".$fileds['z'];
        
$tmp[]="sc=".$fileds['sc'];//贴子总数
        
$tmp[]="cm=".$fileds['cm'];
        
$tmp[]="rn=".$fileds['rn'];
        
$tmp[]="bs=".$fileds['bs'];
        
$tmp[]="str2=".$fileds['str2'];
        
$tmp[]="rs3=".$fileds['rs3'];
        
$tmp[]="bu=".urlencode($url);//这是回跳地址 //window.location
        
$tmp[]="ti=".rawurlencode($title);//标题
        
$tmp[]="ti1=".rawurlencode($title1);
        
$tmp[]="co=".rawurlencode($content);
        
$tmp[]="str1=".rawurlencode($logo);
        
$tmp[]="ch1=on";
        
$tmp[]="Submit3=%B7%A2%B1%ED%CC%F9%D7%D3";
        
$cookie=$this->cookie;
        
$post_data =implode("&",$tmp);
        
$post_data_le = strlen($post_data);
        if(!empty(
$this->proxyPort) and !empty($this->proxyHost)){
            
$post_url="http://tiebacommit.baidu.com/f";
            
$post_port=$this->proxyPort;
            
$connect="Proxy-Connection";
            
$post_host=$this->proxyHost;
        }else{
            
$post_url="/f";
            
$post_port=80;
            
$connect="Connection";
            
$post_host="tiebacommit.baidu.com";
        }
        
$data="POST $post_url HTTP/1.1\nAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\nAccept-Language: zh-cn\nContent-Type: application/x-www-form-urlencoded\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Alexa Toolbar)\nHost: tiebacommit.baidu.com\nContent-Length: $post_data_le\nConnection: Keep-Alive\nCache-Control: no-cache\nCookie: $cookie\n\n$post_data\n";
        
$sock = fsockopen($post_host,$post_port,$errno,$error,3);
        
fputs($sock,$data);
        while (!
feof($sock)) {
            
$rt[]=fgets($sock,1024);
        }
        
fclose($sock);
        
$rt=implode("",$rt);
        
$rt=str_replace("\n","",$rt);
        
$rt=str_replace("\t","",$rt);
        
preg_match_all ("/var rsn=(.+?);/", $rt, $_matches,PREG_SET_ORDER);
        return isset(
$_matches[0][1])?$_matches[0][1]:-99;
    }
    function
_getTie($url="http://post.baidu.com/f?kz=190275966"){
        
$content=$this->_getUrl($url);
        
$title=array();
        
preg_match_all ("/\<input type=hidden name=(.+?) value=(.+?)\>/", $content, $_matches,PREG_SET_ORDER);
        foreach(
$_matches as $value){
            
$key  =trim($value[1]);
            
$v    =str_replace("\"","",trim($value[2]));
            
$title[$key]=($v);
        }
        
preg_match_all ("/fr_as_js_tr\(\)\{(.+)\}/", $content, $_matches,PREG_SET_ORDER);
        
$title['str2']=$this->_getStr2($_matches[0][1]);
        unset(
$title['pn']);
        unset(
$title['kw']);
        unset(
$title['rs2']);
        
preg_match_all ("/var need_verify=(.+?);/", $content, $_matches,PREG_SET_ORDER);
        if(
$_matches[0][1]==10){
            return
null;
        }
        return
$title;
    }
    function
_getStr2($cmd){
        
$cmd = str_replace("var ","",$cmd);
        
$cmd = str_replace("Math.","",$cmd);
        
$cmd = str_replace("v",'$v',$cmd);
        
$cmd = str_replace("i",'$i',$cmd);
        return eval(
$cmd);
    }
    function
_getUrl($url,$referer="")
    {
        
$purl= parse_url($url);
        
$host=$purl['host'];
        if(!empty(
$this->proxyHost) and !empty($this->proxyPort)){
            
$port=$this->proxyPort;
            
$post_host=$this->proxyHost;
        }else{
            
$post_host=$purl['host'];
            if(empty(
$purl['port'])){
                
$port=80;
            }else{
                
$port=$purl['port'];
            }
        }
        
$cookie = $this->cookie;
        
$path=$purl['path'];
        
$query=empty($purl['query'])?"":$purl['query'];
        if(!empty(
$proxyhost) and !empty($proxyport)){
            
$content="";
            
$content.="GET $url HTTP/1.0\r\n";
            
$content.="Accept: */*\r\n";
            if(!empty(
$referer))
            
$content.="Referer: $referer\r\n";
            
$content.="Accept-Language: zh-cn\r\n";
            
$content.="Proxy-Connection: Keep-Alive\r\n";
            
$content.="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n";
            
$content.="Host: $host\r\n";
            
$content.="Pragma: no-cache\r\n";
            
$content.="Cookie: $cookie\r\n";
            
$content.="\r\n\r\n";
        }else{
            
$content="";
            if(!empty(
$query))
            
$content.="GET $path?$query HTTP/1.0\r\n";
            else
            
$content.="GET $path HTTP/1.0\r\n";
            
$content.="Accept: */*\r\n";
            if(!empty(
$referer))
            
$content.="Referer: $referer\r\n";
            
$content.="Accept-Language: zh-cn\r\n";
            
$content.="Connection: Keep-Alive\r\n";
            
$content.="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n";
            
$content.="Host: $host\r\n";
            
$content.="Pragma: no-cache\r\n";
            
$content.="Cookie: $cookie\r\n";
            
$content.="\r\n\r\n";
        }
        
$sock=fsockopen ($post_host,$port,$errno, $errstr, 3);
        if(
$sock){
            
fwrite($sock,$content);
        }else{
            return
null;
        }
        while(
$r[]=fgets($sock)){};
        
fclose($sock);
        return
implode("\n",$r);
    }


}

$baidu = new Baidu_Post;
$baidu->init();
$baidu->login("user","pass");
$baidu->huitie($url,$title,$my_title,$my_content,$my_logo);
$baidu->huitie("http://post.baidu.com/f?kz=199435887","【懂我】为什么排名上不去了 ","我的标题","我的内容","");
?>

下载:baidu.class.rar

上一篇:PayPal全中文详解
下一篇:PHP初级程序员面试题及答案
  • 网友评论:
  • 查看所有评论
  • 我要发表评论
您的网名:
留言主题:
你要发表的内容:

 

关于本站 | 广告联系 | 版权声明 | 网站地图 | 发布软件 | 帮助中心 | 源码论坛

Copyright © 2005-2007 CodePub.Com  程序支持:木翼  滇ICP备05005971号