Getting the price of an amazon product page

Discussion in 'Programming' started by ojsimon, Nov 12, 2007.

  1. #1
    Hi
    The only way i cna think of universally being able to get the price of any amazon product page when a user searches is by using a regular expression. i have no idea how to do this does anyone have any suggetions.

    thanks
     
    ojsimon, Nov 12, 2007 IP
  2. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Amazon do an API (which thankfully supports WDSL). Sign up on their website for an ID and you can then dynamically request any information on a product from price to reviews and recommended cross sells
     
    AstarothSolutions, Nov 12, 2007 IP
  3. ojsimon

    ojsimon Active Member

    Messages:
    459
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    i have an api but i cant find this option i can only find search boxes or inregrated shopping carts
     
    ojsimon, Nov 12, 2007 IP
  4. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #4
    AstarothSolutions, Nov 12, 2007 IP
  5. kemus

    kemus Guest

    Messages:
    487
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Put this in a new file called:
    <?
    function amazonprice($url){
    $data = file_get_contents($url);
    $before= '<td><b class="price">'; // The text immediately before the text you want
    $after = '</b>'; // The text immediately after the text you want.
    // This comments out any special chars in the before or after vars
    $before = preg_quote($before);
    $after=preg_quote($after);
    $match = preg_match($before."(.+?)".$after,$data,$matches);
    if ($match===FALSE)
    {echo "Error, text not found.";}
    else
    {}
    }?>
    
    PHP:
    Put this as the FIRST line of your script (AFTER the first <? tag):
    require_once("inc.amazon.php");
    PHP:
    And now, whenever you want to find the price of an amazon product, assuming you have the url, just do either:

    This to put it in a variable:
    $variable = amazon_price("AMAZON URL HERE");
    PHP:
    Or this to print it to screen:
    echo amazon_price("AMAZON URL HERE");
    PHP:
    Please PM me if you need more help or have more problems.
     
    kemus, Nov 15, 2007 IP