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

一個數據采集類

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

    function seturl($url)
    {
        $this->src_=$url;
    }
    function getcontent()
    {
        return $this->value_;
    }
    function getfile($url)
     // 獲取目標
    {
        $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 用法請參考 curl --help 或者 man curl 
    // curl 參數非常之豐富,可以模擬各種瀏覽器(agent) 可以設置referer
    $cmd="$curl $curl_options $url ";
    @exec($cmd,$o,$r);
    if($r!=0) 
    {
        return "超時";
    }
    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()
     // 開始收集
    {
        $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()
     // 刪除回車換行
    {
        $this->value_=str_replace("/n","",$this->value_);
        $this->value_=str_replace("/r","",$this->value_);
    }


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



    function cut($start,$end,$no='1',$comprise='')
    //'按指定首尾字符串對收集的內容進行裁減(不包括首尾字符串)方法
    // $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='')
    //'按指定首尾字符串對收集的內容用新值進行替換(不包括首尾字符串)方法
    // '參數分別是首字符串,尾字符串,新值,新值位空則為過濾
    {
        $tmp_v=$this->value_;
        $tmp=$this->cut($head,$bot,$no,$comprise);
        return $this->value_=str_replace($tmp,$str,$tmp_v);
    }



    function  local()
    {
        //'將收集的內容中的絕對URL地址改為本地相對地址
        // 還沒實現
    }



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



    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;
    }


}
?>

php技術一個數據采集類,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 真实国产乱子伦久久 | 亚洲一区免费视频 | www.91色.com| 亚洲一区二区免费看 | 欧美性在线观看 | 久久99国产精品二区不卡 | 国产在线拍揄自揄视精品不卡 | 国产91一区二区在线播放不卡 | 国产乱码一区二区三区四川人 | 一本色道久久88加勒比—综合 | 日本不卡一区二区三区在线观看 | 久草热在线视频 | 亚洲伊人久久大香线蕉结合 | 亚洲爱视频| 天天澡天天碰天天狠伊人五月 | 精品日韩在线 | 精品久久久久久综合日本 | 在线播放色| 欧美人爱视频 | 伊人任线任你躁 | 日韩专区亚洲国产精品 | 精品国产成人高清在线 | 亚洲精品三区 | 97一区二区三区四区久久 | 五月天丁香婷婷开心激情五月 | 精品视频自拍 | 久久永久免费视频 | 色天使色护士 在线视频观看 | 四虎影视久久久 | 91精品国产福利尤物 | 97久久人人| 亚洲福利国产 | caoporn97人人做人人爱最新 | 国产在线拍 | 色喔喔| 国色天香网站 | 91免费版视频 | 天天色天天射天天干 | 激情综合文学 | 国产手机精品视频 | 第一页综合 |