娱乐新地带论坛  

返回   娱乐新地带论坛 > 电脑技术 > 『程序设计』

『程序设计』 不太懂编程,主要用来搜集例子,源码等...

发表新主题 回复
 
主题工具 显示模式
旧 2006-02-15, 01:48 PM   #1
No1
Tony
坛主
级别:199 | 在线时长:40418小时 | 升级还需:382小时级别:199 | 在线时长:40418小时 | 升级还需:382小时级别:199 | 在线时长:40418小时 | 升级还需:382小时级别:199 | 在线时长:40418小时 | 升级还需:382小时
 
Tony 的头像
 
注册日期: 2003-10-22
帖子: 11,050
积分:6
精华:24
现金:14340金币
资产:29325297金币
Tony 是一位成功的新星Tony 是一位成功的新星Tony 是一位成功的新星Tony 是一位成功的新星
先锋海盗类(php版)——php写小偷程序的工具

PHP 代码:
<?
//////////////////////////////////////////////////////////////
//
//      统一搜集系统 Univeral Gather System (UGS)
//      作者 [email]zj@52linux.com[/email] 
//      主页 [url]http://www.52linux.com[/url]
//      联系QQ 733905
//         类内函数
//         steal 用于搜集页面文字
//         cut/cutpro 用于剪切文字
//         filt/filtx用于过滤文字
//         change用于改变文字
//         getenterkey用于获得关键位置的链接Array
//         _striplinks和_striptext 用于产生锚点的Array和文字
//
//////////////////////////////////////////////////////////////
class ugs
{
     var 
$value_  ;  //'窃取到的内容
     
var $src_    ;  //'要偷的目标URL地址
     
var $isGet_   //判断是否已经偷过

    
function BytesToBstr($f//'变成1行
     
{
           return 
join("",$f);
      
     }
     function 
_striptext() //取得文字内容
     
{
           
           
// I didn't use preg eval (//e) since that is only available in PHP 4.0.
           // so, list your entities one by one here. I included some of the
           // more common ones.
                                               
           
$search = array("'<script[^>]*?>.*?</script>'si",      // strip out javascript
                                   
"'<[\/\!]*?[^<>]*?>'si",                  // strip out html tags
                                   
"'([\r\n])[\s]+'",                              // strip out white space
                                   
"'&(quot|#34|#034|#x22);'i",            // replace html entities
                                   
"'&(amp|#38|#038|#x26);'i",                  // added hexadecimal values
                                   
"'&(lt|#60|#060|#x3c);'i",
                                   
"'&(gt|#62|#062|#x3e);'i",
                                   
"'&(nbsp|#160|#xa0);'i",
                                   
"'&(iexcl|#161);'i",
                                   
"'&(cent|#162);'i",
                                   
"'&(pound|#163);'i",
                                   
"'&(copy|#169);'i",
                                   
"'&(reg|#174);'i",
                                   
"'&(deg|#176);'i",
                                   
"'&(#39|#039|#x27);'",
                                   
"'&(euro|#8364);'i",                        // europe
                                   
"'&a(uml|UML);'",                              // german
                                   
"'&o(uml|UML);'",
                                   
"'&u(uml|UML);'",
                                   
"'&A(uml|UML);'",
                                   
"'&O(uml|UML);'",
                                   
"'&U(uml|UML);'",
                                   
"'&szlig;'i",
                                   );
           
$replace = array(      "",
                                         
"",
                                         
"\\1",
                                         
"\"",
                                         
"&",
                                         
"<",
                                         
">",
                                         
" ",
                                         
chr(161),
                                         
chr(162),
                                         
chr(163),
                                         
chr(169),
                                         
chr(174),
                                         
chr(176),
                                         
chr(39),
                                         
chr(128),
                                         
"?",
                                         
"?",
                                         
"?",
                                         
"?",
                                         
"?",
                                         
"?",
                                         
"?",
                                   );
                             
           
$text preg_replace($search,$replace,$this->value_);
                                               
           return 
$this->value_=$text;
     }
     function 
_striplinks() //取得链接Array 
     
{      
           
preg_match_all("'<\s*a\s.*?href\s*=\s*                  # find <a href=
                                   ([\"\'])?                              # find single or double quote
                                   (?(1) (.*?)\\1 | ([^\s\>]+))            # if quote found, match up to next matching
                                                                             # quote, otherwise match up to next space
                                   'isx"
,$this->value_,$links);
                                   

           
// catenate the non-empty matches from the conditional subpattern

           
while(list($key,$val) = each($links[2]))
           {
                 if(!empty(
$val))
                       
$match[] = $val;
           }                        
           
           while(list(
$key,$val) = each($links[3]))
           {
                 if(!empty(
$val))
                       
$match[] = $val;
           }            
           
           
// return the links
           
return $this->value_=$match;
     }


     function   
steal($toline=true//'窃取目标URL地址的HTML代码的方法
     
{
            
           if(
$this->src_!="")
           {
                 
$unix=true//如果您是unix系统 请设置true 条件是系统里有wget 这个软件,如果是window系统,设置为false,或者当有wget.exe 这个软件时也可以设置为true
                 // wget.exe 可从下面地址得到  [url]http://allserv.ugent.be/~bpuype/wget/[/url] 
                 
if($unix){
                 
$tmpfile=tempnam("/tmp","FOO");

                 
$cmd="wget -nv -O $tmpfile \"$this->src_\"";
                 
//echo $cmd;
                 
exec($cmd);

                 
$http=file($tmpfile);

                 
unlink($tmpfile);

                 }
                 else
                 {
                 
$http=file($this->src_);
                 
                 }

                 
//print_r($http);
                 
if($toline) {
                 
$this->isGet_=true;
                 return 
$this->value_=$this->BytesToBstr($http);
                  
                 }
                 else
                 {
                 
$this->isGet_=true;
                  
                 return 
$this->value_=$http;
                 
                 }
           }
           else
           {
                  
                 echo (
"<script>alert(\"请先设置src属性!\")</script>");
           }
     

     }
           function 
steal_local($toline=true)  // 此方法为处理本地文件使用 
     
{
           if(
$this->src_!="")
                 {
                       if(
$toline
                       {
                             
$http=file($this->src_);
                             
$this->isGet_=true;
                             return 
$this->value_=$this->BytesToBstr($http);
                              
                       }
                       else
                       {
                             
$http=file($this->src_);
                             
$this->isGet_=true;
                             return 
$this->value_=$http;
                             
                       }
                       
                 }
           else
                 {

                 echo (
"<script>alert(\"请先设置src属性!\")</script>");
                 }
            
           
     }


     
//'删除偷到的内容中里面的换行、回车符以便进一步加工/方法
     
function noReturn() 
     {
            
     if(!
$this->isGet_$this->steal();
     
$this->value_=str_replace("\n","",$this->value_);
     
$this->value_=str_replace("\r","",$this->value_);
     }

     
//'对偷到的内容中的个别字符串用新值更换/方法
     
function change($oldStr,$str//'参数分别是旧字符串,新字符串
     
{
     if(!
$this->isGet_$this->steal();
     
$this->value_=str_replace($oldStr,$str,$this->value_ );
     }



     
//'按指定首尾字符串对偷取的内容进行裁减(不包括首尾字符串)/方法
     
function  cut($head,$bot//'参数分别是首字符串,尾字符串
     
{
                 if(!
$this->isGet_$this->steal();

                 
$message=explode($head,$this->value_);

                 if(
count($message)>1)
                 {
                       
$message=explode($bot,$message[1]);
                       return 
$this->value_$message[0];
                 }
                 else 
                 {
                       return 
$this->value_="";
                 }
      
     
     }
     

     function 
cutpro($start,$end,$no='1',$comprise=''// $no must in {1,2,3,4,5.....} zero is not support
           //此方法较cut方法有进步,是可以调节$no 确定切到指定第no个符合条件的文字串
           
{  
                
$string=explode($start,$this->value_);
                       
//print_r($string);
                
$string=explode($end,$string[$no]);
                       
//print_r($string);
                
switch ($comprise){
                        case 
'start':
                                
$string=$start.$string[0];
                        break;
                        case 
'end':
                                
$string=$string[0].$end;
                        break;
                        case 
'all':
                                
$string=$start.$string[0].$end;
                        break;
                        default:
                                
$string=$string[0];
                }
                return 
$this->value_=$string;
        }

     function 
cut2($head,$bot)  //cut 的另一种实现方法
     
{
           return  
substr($this->value_,strpos($this->value_,$head)+strlen($head),strpos($this->value_,$bot)-strpos($this->value_,$head)-strlen($head));
     }

     
//'按指定首尾字符串对偷取的内容进行裁减(包括首尾字符串)/方法
     
function  cutX($head,$bot//'参数分别是首字符串,尾字符串
     
{
                 
$tmp=$this->cut($head,$bot);
                 
                 return 
$this->value_=$head.$tmp.$bot;
                  
     
     }


     
//'按指定首尾字符串位置偏移指针对偷取的内容进行裁减/方法
     
function cutBy($head,$headCusor,$bot,$botCusor
     
//'参数分别是首字符串,首偏移值,尾字符串,尾偏移值,左偏移用负值,偏移指针单位为字符数
     
{
     if(!
$this->isGet_$this->steal();
     return 
substr($this->value_,strpos($this->value_,$head)+strlen($head)+$headCusor,strpos($this->value_,$bot)-1+$botCusor-strpos($this->value_,$head)-strlen($head)-$headcusor);
        
     }


     
//'按指定首尾字符串对偷取的内容用新值进行替换(不包括首尾字符串)/方法
     
function  filt($head,$bot,$str)// '参数分别是首字符串,尾字符串,新值,新值位空则为过滤
     
{
           if(!
$this->isGet_$this->steal();
           
$tmp_v=$this->value_;
           
$tmp=$this->cut($head,$bot);
           return 
$this->value_=str_replace($tmp,$str,$tmp_v);
     }

     function  
filtX($head,$bot,$str)// '参数分别是首字符串,尾字符串,新值,新值位空则为过滤
     
{
           if(!
$this->isGet_$this->steal();
           
$tmp_v=$this->value_;

           
$tmp=$this->cutX($head,$bot);
            
           return 
$this->value_=str_replace($tmp,$str,$tmp_v);
     }

     
//'按指定首尾字符串位置偏移指针对偷取的内容新值进行替换/方法
     
function  filtBy($head,$headCusor,$bot,$botCusor,$str
     
//'参数分别是首字符串,首偏移值,尾字符串,尾偏移值,新值,左偏移用负值,偏移指针单位为字符数,新值为空则为过滤
     
{
     if(!
$this->isGet_$this->steal();
     
// 这里写代码  
     
$tmp_v=$this->value_;
     
$ttt=substr($this->value_ ,strpos($this->value_ ,$head)+strlen($head)+$headCusor,strpos($this->value_ ,$bot)-1+$botCusor-strpos($this->value_ ,$head)-strlen($head)-$headCusor);
     
//echo $ttt;
     
return $this->value_=str_replace($ttt,$str,$tmp_v );

     }
     
     
//'将偷取的内容中的绝对URL地址改为本地相对地址
     
function  local()
     {

     }


     
//'对偷到的内容中的符合正则表达式的字符串用新值进行替换/方法
     
function  replaceByReg($patrn,$str//'参数是你自定义的正则表达式,新值
     
{
     if(!
$this->isGet_$this->steal();
     return 
$this->value_=join("",preg_replace($patrn,$str,$this->value_));
      
     }

     function 
pickByReg($patrn)
     {
     
//  
     
}

     function 
debug()
     {
           
$tempstr="<SCRIPT>function runEx(){var winEx2 = window.open(\"\", \"winEx2\", \"width=500,height=300,status=yes,menubar=no,scrollbars=yes,resizable=yes\"); winEx2.document.open(\"text/html\", \"replace\"); winEx2.document.write(unescape(event.srcElement.parentElement.children[0].value)); winEx2.document.close(); }function saveFile(){var win=window.open('','','top=10000,left=10000');win.document.write(document.all.asdf.innerText);win.document.execCommand('SaveAs','','javascript.htm');win.close();}</SCRIPT><center><TEXTAREA id=asdf name=textfield rows=32  wrap=VIRTUAL cols=\"120\">".$this->value_."</TEXTAREA><BR><BR><INPUT name=Button onclick=runEx() type=button value=\"查看效果\">  <INPUT name=Button onclick=asdf.select() type=button value=\"全选\">  <INPUT name=Button onclick=\"asdf.value=''\" type=button value=\"清空\">  <INPUT onclick=saveFile(); type=button value=\"保存代码\"></center>";
        echo 
$tempstr;
     }

     function 
getkeylinks($key// 此方法用来确定包含某关键字的行的所有链接情况
     
{
           
// this function is used for toline=false 
           
if(!$this->isGet_$this->steal();
           foreach(
$this->value_ as $k=>$v)
           {
                 if(
ereg($key,$v)) {
                       
$this->value_=$v;
                       return 
$this->value_=$this->_striplinks();
                 }
           }
           
     }
     function 
hasit($key)  // 此方法用来确定是否包含某关键字的行 
     
{
           
// this function is used for toline=false and true;
           
if(!$this->isGet_$this->steal();
      
           foreach(
$this->value_ as $k=>$v)
           {
                 if(
ereg($key,$v))
                 {
                        
                 return 
true;
                 }
                 
           }

           return 
false;
     }
     

}
?>
Tony 当前离线  
回复时引用此帖
旧 2006-02-15, 01:49 PM   #2
No1
Tony
坛主
级别:199 | 在线时长:40418小时 | 升级还需:382小时级别:199 | 在线时长:40418小时 | 升级还需:382小时级别:199 | 在线时长:40418小时 | 升级还需:382小时级别:199 | 在线时长:40418小时 | 升级还需:382小时
 
Tony 的头像
 
注册日期: 2003-10-22
帖子: 11,050
积分:6
精华:24
现金:14340金币
资产:29325297金币
声望: 395
Tony 是一位成功的新星Tony 是一位成功的新星Tony 是一位成功的新星Tony 是一位成功的新星
补充一个原作者现在发布的ups.class.php
PHP 代码:
<?php
/**
// 程序作者:张建
// 网站:http://www.phpsir.com
// 联系方法:52linux@gmail.com
// 联系方法:QQ 733905
//

示例:
include ("ugs.php"); // 你可以下载本ugs.phps 然后重命名为ugs.php
$ugs = new ugs();
$url = "http://domainname.com/path_to_your_target?param";
$ugs->set($url);
$ugs->gus();
以满足您的要求
$content=$ugs->get();
print($content);

======================================================
使用方法

include ("ugs.php");

$ugs = new ugs();
$url = "http://domainname.com/path_to_your_target?param";
$ugs->set($url);
$ugs->gus();
$content=$ugs->get();
print($content);


*/
class    ugs
{
var 
$value_  ;  //'目标内容
var $src_    ;  //'目标URL地址

function    set($url)
{
    
$this->src_=$url;
}

function    
get()
{
    return 
$this->value_;
}


function    
gus()
{
    
$this->value_=file_get_contents($this->src_); //(PHP 4 >= 4.3.0, PHP 5)
}

function    
gaa()
{
    
$this->value_=file($this->src_);
}

function    
nor()     // 删除回车换行
{
    
$this->value_=str_replace("\n","",$this->value_);
    
$this->value_=str_replace("\r","",$this->value_);
}

function    
chg($oldstr,$newstr//'对收集到的内容中的个别字符串用新值更换的方法,参数分别是旧字符串,新字符串
{
    
$this->value_=str_replace($oldstr,$newstr,$this->value_ );
}

function    
cut($StartFlag,$EndFlag,$no='1',$comprise='')
/*
按指定首尾字符串对收集的内容进行裁减的的方法
$no 必须是 1,2 3 ... 不允许 0
$comprise 可以选择 start 或者 end 或者 all 或者 什么都不填
*/
{
    
$string=explode($StartFlag,$this->value_);
    
//print_r($string);
    
$string=explode($EndFlag,$string[$no]);
    
//print_r($string);
    
switch ($comprise){
            case 
'start':
                    
$string=$StartFlag.$string[0];
            break;
            case 
'end':
                    
$string=$string[0].$EndFlag;
            break;
            case 
'all':
                    
$string=$StartFlag.$string[0].$EndFlag;
            break;
            default:
                    
$string=$string[0];
    }
    return 
$this->value_=$string;

}


function    
flt($start,$end,$newstr,$no='1',$comprise='')
/*
按指定首尾字符串对收集的内容用新值进行替换(不包括首尾字符串)方法
参数分别是首字符串,尾字符串,新值,新值位空则为过滤
*/
{
    
$tmp_ori=$this->value_;
    if(
$comprise==''){
        
$tmp=$this->cut($start,$end,$no);
    }else{
        
$tmp=$this->cut($start,$end,$no,$comprise);
    }

    
$this->value_=str_replace($tmp,$newstr,$tmp_ori);
}

function 
dbg() //调试显示
{
    
$tempstr="<SCRIPT>function runEx(){var winEx2 = window.open(\"\", \"winEx2\", \"width=500,height=300,status=yes,menubar=no,scrollbars=yes,resizable=yes\"); winEx2.document.open(\"text/html\", \"replace\"); winEx2.document.write(unescape(event.srcElement.parentElement.children[0].value)); winEx2.document.close(); }function saveFile(){var win=window.open('','','top=10000,left=10000');win.document.write(document.all.asdf.innerText);win.document.execCommand('SaveAs','','javascript.htm');win.close();}</SCRIPT><center><TEXTAREA id=asdf name=textfield rows=32  wrap=VIRTUAL cols=\"120\">".$this->value_."</TEXTAREA><BR><BR><INPUT name=Button onclick=runEx() type=button value=\"查看效果\">&nbsp;&nbsp;<INPUT name=Button onclick=asdf.select() type=button value=\"全选\">&nbsp;&nbsp;<INPUT name=Button onclick=\"asdf.value=''\" type=button value=\"清空\">&nbsp;&nbsp;<INPUT onclick=saveFile(); type=button value=\"保存代码\"></center>";
    echo 
$tempstr;
}


}
?>
Tony 当前离线  
回复时引用此帖
发表新主题 回复

书签


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码

论坛跳转


所有时间均为北京时间。现在的时间是 06:21 AM


©2003-2024 1819.net All rights reserved.