Small Grabber demo based on OOP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Small Grabber demo based on OOP

    We Got 2 files for use


    grab_lib.php && index.php




    OOP BASED SCRIPT :
    grab_lib.php


    PHP Code:
    <?php  
    class grabber{

    var 
    $grab;

    function 
    page($url,$mode){

    //empty ? // fallin' back to file_get_contents
    if (empty($mode)){$mode='fget';} 

    if (
    $mode=='fget'){

    $opts = array(
      
    'http'=>array(
        
    'method'=>"GET",
        
    'header'=>"Accept-language: en\r\n" .
                  
    "User-Agent: SAMSUNG-SGH-E250/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0 (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)\r\n"
      
    )
    );

    $context stream_context_create($opts);

    // Send HTTP headers set above thiss allow us to set browser model
    $page=file_get_contents($urlfalse$context);
    $ret $this->grab=$page;
    }

    if (
    $mode=='curl'){
    $crl curl_init();
    curl_setopt ($crlCURLOPT_URL,$url);
    curl_setopt ($crlCURLOPT_RETURNTRANSFER1);
    curl_setopt($crl,CURLOPT_USERAGENT,'SAMSUNG-SGH-E250/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0 (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)');
    //Make sure its sent , send user agent via header to 
    curl_setopt ($crlCURLOPT_HTTPHEADER,array('User-Agent: SAMSUNG-SGH-E250/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0 (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html),'));
    curl_setopt($crlCURLOPT_FOLLOWLOCATION1);
    $grab curl_exec($crl); curl_close($crl);
    $page=$grab;
    $ret $this->grab=$page;
    }

    //echo 'Using '.$mode.' fetching contents';
    return $ret; }

    }

    ?>


    CLASSIC PHP :
    index.php


    PHP Code:
    <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Here is my link grabber demo</title>
    </head>

    <body>
    <?php
    ###############################
    require_once'grab_lib.php';   #
    ###############################

    $grab = new grabber();

    ########### FILE LINKS ONLY ############ 

    $moddmydata $grab->page('http://whatmp3.name/search.php?query=house+base','curl');

    // make local links 
    $moddmydata str_replace("http://whatmp3.name/","",$moddmydata);
    // remove all div's on page 
    $moddmydata preg_replace('/<div(.*?)>/is','',$moddmydata);
    $moddmydata str_replace('</div>','',$moddmydata);
    // remove all scripts on page 
    $moddmydata preg_replace('/<script(.*?)<\/script>/is','',$moddmydata);
    // remove all images
    $moddmydata preg_replace('/<img(.*?)>/is','',$moddmydata);
    // here you can mod the links
    $moddmydata preg_replace('/<a href="download.php(.*?)">/is','<a href="my_file.php$1&act=download">',$moddmydata); 
    // remove all ads links ussualy starts with http:// 
    //site links should be local pointing like /file.php?file=12453
    $moddmydata preg_replace('/<a href="http:\/\/(.*?)<\/a>/is','',$moddmydata); 
    $moddmydata preg_replace("/(.*?)<a href=\"(.*?)<\/a>/is","<a href=\"$2</a></br>\n",$moddmydata); 
    $moddmydata preg_replace("/<!--(.*?)<\/html>/is","",$moddmydata);
    echo 
    $moddmydata;
    ?>



    </body>
    </html>

    you can use this class for easy switching between grabbing methods file_get_contents (fget) and curl both methods implemented with user agent .

    class attached bellow
    Attached Files
    This is ten percent luck, twenty percent skill
    Fifteen percent concentrated power of will
    Five percent pleasure, fifty percent pain

    And a hundred percent reason to remember the name!
Working...
X