11

<?php
 class Thief{
  var $URL;
  function getSourceList ()
  {
    var $sList = @file_get_contents( $this->URL );
       preg_match_all( "/<a(.*?)<\/a>/i", $sList, $list );
       $list = $list[0];
    if(!$list || !is_array($list)){
        return $this->getSourceListExtend($sList);
    }else{
        return $this->getList ( $list );
    }                                         
  }
 
  function getSourceListExtend($sList)
  {
    $content=explode("</a>",$sList);
    for($i=0;$i<count($content)-1;$i++)
    {
        $lists=explode("<a",$content[$i]);
                $list[]=$lists[1];
    }
    return $this->GetListExtend( $list );
  }
  function getList ( $list )
  {
    for ( $i = 0; $i < count( $list ); $i++ )
    {               
        preg_match_all( "/href=(\"|'|)(.*?)(\"|'|)/i", $list[$i], $tempc );
            //获取的数据正确
            if( !empty( $templ[1][0] ) && !empty( $tempc[2][0] ) )
            {
            if( 0 == strpos( $tempc[2][0], "/" ) )
            {
                preg_match( "@http://(.*?)/@i", $this->URL, $url );
                $tempc[2][0] = substr( $url[0], 0, strlen( $url[0] ) - 1 ) . $tempc[2][0];
            }
            $listContent[$i][1] = $tempc[2][0];
            }
     }
    if(!$listContent || !is_array($listContent)){
        return $this->GetListExtend ( $list );
    }else{
        return $listContent;
    }
  }

  function GetListExtend ( $list )
  {                 
    $list=str_replace("\"","",$list);
    $list=str_replace("'","",$list);
    $list=str_replace("=","",$list);
       for ( $i = 0; $i <count( $list ); $i++ )
       {    
            $temp_link=$this->cut($list[$i],"href"," ");
            //获取的数据正确
        if( !empty( $temp_link ))
        {
            if( 0 == strpos( $tempc[2][0], "/" ) )
            {
            }
            $listContent[$i][1] = $temp_link;
        }
    }
    return $listContent;
  }
 }

?>

posted @ 2014-03-12 00:35  曹桦伟  阅读(201)  评论(0编辑  收藏  举报