1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP Script for Amazon

Discussion in 'PHP & Perl' started by blackjack, Oct 26, 2008.

  1. blackjack

    blackjack Regular Member

    Joined:
    Nov 23, 2007
    Messages:
    276
    Likes Received:
    51
    Hi

    I am not sure if this is the correct place to ask this question. Please move it if this is not correct category.

    I am looking for a PHP script for Amazon which searches based on Asin Number not search keyword. Is there any thing link this available.

    The basic things are

    1. Create a config.php file with Amazon site selection, Amazon dev id, Amazon affiliate ID and Amazon ASIN

    2. Use PHP to get the following information Product Name, Price, Description, Image and customer review. Then populate a template with that information.

    Thanks for your time.
     
  2. knowledgeblast

    knowledgeblast Jr. VIP Jr. VIP Premium Member

    Joined:
    Jul 31, 2008
    Messages:
    523
    Likes Received:
    62
    I'd be interested in something like this myself....I'd also like to know the best amazon script to create profits with?

    Thanks all
     
  3. cyklotrial

    cyklotrial Regular Member

    Joined:
    Oct 13, 2008
    Messages:
    248
    Likes Received:
    82
    Location:
    Wonderland
    PHP:
    <?php
    $c 
    curl_init();

    curl_setopt($cCURLOPT_URL'http://www.amazon.co.uk/dp/0261102389/');//connect to amazon site
    curl_setopt($cCURLOPT_HEADER1);
    curl_setopt($cCURLOPT_VERBOSE1);
    curl_setopt($cCURLOPT_RETURNTRANSFER,1);
    curl_setopt($cCURLOPT_USERAGENT'Mozilla/5.0 (X11; U; Linux i686;pl; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3');
    curl_setopt($cCURLOPT_ENCODING'gzip');
    curl_setopt($cCURLOPT_ENCODING'deflate');
    curl_setopt($cCURLOPT_ENCODING'');
    curl_setopt($cCURLOPT_FOLLOWLOCATION1);

    $page curl_exec($c);


    $title explode('<span id="btAsinTitle"',$page);
    $title explode('>',$title[1]);
    $title explode('</span>',$title[1]);


    echo 
    $title[0];
    ?>
    This code take only title but you can do the same with description,price etc.
    You only need for this ASIN database. Ofcourse you can use brutal method for this:
    http://www.amazon.co.uk/dp/[B]0000000001[/B]
    http://www.amazon.co.uk/dp/[B]0000000002[/B]
    http://www.amazon.co.uk/dp/[B]0000000003[/B]
    etc
    but you will get ban for ip adress shortly

    tomorrow i will give you better code


    Click thanks if I helped ;)
     
    • Thanks Thanks x 1
  4. blackjack

    blackjack Regular Member

    Joined:
    Nov 23, 2007
    Messages:
    276
    Likes Received:
    51
    Thanks. I have no idea how does this code work? Look forward to your better code tomorrow.

    Thanks
     
  5. cyklotrial

    cyklotrial Regular Member

    Joined:
    Oct 13, 2008
    Messages:
    248
    Likes Received:
    82
    Location:
    Wonderland
    PHP:
    <?php
    //----------------- CONECT SECTION
    function connect($url)
    {

        
    $a curl_init();
        
    curl_setopt($aCURLOPT_URL"$url");//connect to amazon site
        
    curl_setopt($aCURLOPT_HEADER1);//send header
        
    curl_setopt($aCURLOPT_VERBOSE1);
        
    curl_setopt($aCURLOPT_RETURNTRANSFER,1);
        
    curl_setopt($aCURLOPT_USERAGENT'Mozilla/5.0 (X11; U; Linux i686;pl; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3');//send usragent
        
    curl_setopt($aCURLOPT_ENCODING'gzip');
        
    curl_setopt($aCURLOPT_ENCODING'deflate');
        
    curl_setopt($aCURLOPT_ENCODING'');
        
    curl_setopt($aCURLOPT_FOLLOWLOCATION1);
        global 
    $page;
        
    $page curl_exec($a);//put html code into $page variable
    }    
    //-----------------END CONECT SECTION

    connect('http://www.amazon.co.uk/dp/0261102389');//You should take this url from database 

    //-----------------START TAKING DATA
    /////////////////////////////////////////////////////////////////////////////
    //example
    //        $text=ABCD;
    //        $title = explode('A',$text);            satrt searching after A
    //        $title = explode('B',$title[1]);            B is left limit
    //        $title = explode('D',$title[1]);             D is right limit
    //        echo $title[0];                    this will show C
    ////////////////////////////////////////////////////////////////////////////

    $title explode('<span id="btAsinTitle"',$page);//start search title from here
    $title explode('>',$title[1]);//Take data from here
    $title explode('</span>',$title[1]);//to here 


    $price explode('<span class="price"',$page);
    $price explode('>',$price[1]);
    $price explode('</span>',$price[1]);


    $description explode('<h2>Product Description</h2>',$page);
    $description explode('<div class="content">',$description[1]);
    $description explode('<img src=',$description[1]);

    //Now we can save this in database
    //    EXAMPLE
    //    $sql = mysql_connect (localhost, 'root', 'krasnal');
    //    $dbase=mysql_select_db('amazon_db');
    //    $query = "INSERT INTO `amazon` (`Id`, `Title`, `Price`, `Descyprion`) VALUES ('', '$title[0]', '$price[0]', '$description[0]')";
    //    $save = mysql_query($query);
    ?>
    For now i have no idea how to take all image's and customer review's because his number is not constant.
    Certainly it is possible to make it, but now i don't have idea how to check how many it is.
    regards