一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

一個(gè)數(shù)據(jù)采集類(lèi)

復(fù)制代碼 代碼如下:
<?
// 兼容 phpphp5
// 程序作者  張建 52linux.com(我愛(ài)Linux)
// 聯(lián)系方法  733905@qq.com  QQ 733905 
// 簡(jiǎn)單調(diào)用方法
/*
<?
include ("ugs.php"); // 你可以下載本ugs.phps 然后重命名為ugs.php
$ugs = new ugs();
$url = "http://domainname.com/path_to_your_target?param";
$ugs->seturl($url);
$ugs->gather();
//............這里可以調(diào)用本類(lèi)里的其它方法,對(duì)$ugs->value_  做調(diào)整,
以滿足您的要求
$content=$ugs->getcontent();
print($content);
?>
*/
class ugs
{
    var $value_  ;  //'目標(biāo)內(nèi)容
    var $src_    ;  //'目標(biāo)URL地址

    function seturl($url)
    {
        $this->src_=$url;
    }
    function getcontent()
    {
        return $this->value_;
    }
    function getfile($url)
     // 獲取目標(biāo)
    {
        $url_parsed = parse_url($url);
        $host = $url_parsed["host"];
        $port = $url_parsed["port"];
        if ($port==0)  $port = 80;
        $path = $url_parsed["path"];
        if (empty($path))
        $path="/";
        if ($url_parsed["query"] != "")
           $path .= "?".$url_parsed["query"];
        $out = "GET $path HTTP/1.0/r/nHost: $host/r/n/r/n";
        $fp = fsockopen($host, $port, $errno, $errstr, 30);
        fwrite($fp, $out);
        $body = false;
        while (!feof($fp))
        {
          $s = fgets($fp, 1024);
          if ( $body )  $in .= $s;
          if ( $s == "/r/n" )
               $body = true;
        }
        fclose($fp);
        return $in;
   }

   function getfile_curl($url)
   {
    $curl="/usr/local/bin/curl " ; // path to your curl 
    $curl_options=" -s --connect-timeout 10  --max-time 10  "; 
    // curl 用法請(qǐng)參考 curl --help 或者 man curl 
    // curl 參數(shù)非常之豐富,可以模擬各種瀏覽器(agent) 可以設(shè)置referer
    $cmd="$curl $curl_options $url ";
    @exec($cmd,$o,$r);
    if($r!=0) 
    {
        return "超時(shí)";
    }
    else
    {
        $o=join("",$o);
        return $o;
    }
   }

    function gather_curl($curl)
    {
        $http=$this->getfile_curl($this->src_);
        return $this->value_=$http;
    }

    function gather_array($url)
     {
        return file($url);
    }

    function   gather()
     // 開(kāi)始收集
    {
        $http=$this->getfile($this->src_);
        return $this->value_=$http;
    }

    function gather_local($toline=true)
     // 處理本地文件
    {

        if($toline)
        {
            $http=file($this->src_);
            return $this->value_=$this->BytesToBstr($http);
        }
        else
        {
            $http=file($this->src_);
            return $this->value_=$http;
        }



    }

    function noReturn()
     // 刪除回車(chē)換行
    {
        $this->value_=str_replace("/n","",$this->value_);
        $this->value_=str_replace("/r","",$this->value_);
    }


    function change($oldStr,$str)
    //'對(duì)收集到的內(nèi)容中的個(gè)別字符串用新值更換/方法
    //'參數(shù)分別是舊字符串,新字符串
    {
        $this->value_=str_replace($oldStr,$str,$this->value_ );
    }



    function cut($start,$end,$no='1',$comprise='')
    //'按指定首尾字符串對(duì)收集的內(nèi)容進(jìn)行裁減(不包括首尾字符串)方法
    // $no 必須是 1,2 3 ... 不允許是0
    //$comprise 可以選擇 start 或者 end 或者 all 或者 什么都不填
    {
        $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  filt($head,$bot,$str,$no='1',$comprise='')
    //'按指定首尾字符串對(duì)收集的內(nèi)容用新值進(jìn)行替換(不包括首尾字符串)方法
    // '參數(shù)分別是首字符串,尾字符串,新值,新值位空則為過(guò)濾
    {
        $tmp_v=$this->value_;
        $tmp=$this->cut($head,$bot,$no,$comprise);
        return $this->value_=str_replace($tmp,$str,$tmp_v);
    }



    function  local()
    {
        //'將收集的內(nèi)容中的絕對(duì)URL地址改為本地相對(duì)地址
        // 還沒(méi)實(shí)現(xiàn)
    }



    function  replaceByReg($patrn,$str)
     //'對(duì)收集的內(nèi)容中的符合正則表達(dá)式的字符串用新值進(jìn)行替換/方法
     //'參數(shù)是你自定義的正則表達(dá)式,新值
    {
        return $this->value_=join("",preg_replace($patrn,$str,$this->value_));
    }



    function debug()
    //調(diào)試顯示
    {
        $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;
    }


}
?>

php技術(shù)一個(gè)數(shù)據(jù)采集類(lèi),轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 婷婷的五月 | 四虎永久在线精品国产免费 | 2019偷偷狠狠的日日 | 亚洲黄色免费在线观看 | 国产视频一二区 | 伊人久久香| 欧美www在线观看 | 欧美日韩一二三四区 | 91久久精品国产91性色tv | 久久久久久亚洲精品中文字幕 | 丁香欧美| 亚洲免费视频网站 | 综合久久久久 | 欧美日韩黄色大片 | 91视频站| 深爱五月婷婷 | 日韩视频第一页 | 成人sese| 欧美黑人xxxxx性受 | 久久久精品国产四虎影视 | 国产午夜三区视频在线 | 白白在线成人永久视频 | 中国美女一级毛片 | 久久tv| 91久久亚洲最新一本 | 加勒比视频网站 | 91网站国产 | av基地| 深夜影院深a| 国内精品一区二区2021在线 | 一级做a爰片性色毛片2021 | 国产视频福利在线 | 成年人天堂 | 国产美女精品 | 高清免费久久影院 | 九月婷婷亚洲综合在线 | 欧美地区一二三区 | 国产在线2021| 真人视频一级毛片 | 亚洲一区二区中文字5566 | 亚洲精品国产第1页 |