Help: GE Price Grabber

Discussion in 'Web Programming' started by Jon_d2, Feb 20, 2009.

Help: GE Price Grabber
  1. Unread #1 - Feb 20, 2009 at 5:30 PM
  2. Jon_d2
    Joined:
    Feb 20, 2009
    Posts:
    14
    Referrals:
    0
    Sythe Gold:
    0

    Jon_d2 Newcomer

    Help: GE Price Grabber

    Ok, So i'm developing a script in PHP that will grab the price from the Runescape website of items on the grand exchange. I have completed the HTML grabbing, now all i need to do is scan though the HTML and take out the price. I have a good idea about how to go about doing this, by using regular expressions. But I can't seem to find a way to take out what's infront of "market price:", "maximum price:", and "minimum price:". Here is my script so far:

    <?php

    $ch = curl_init();
    $id = "9004";
    curl_setopt($ch, CURLOPT_URL, "http://itemdb-rs.runescape.com/viewitem.ws?obj=".$id);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    curl_close($ch);

    $string = $output;

    if(preg_match("/market price:/i", $string))
    {
    echo 'Matched Found';
    }else{
    echo 'No match found';
    }


    ?>

    As you can see, I don't have a way to take out the value that comes after the market price.

    I have been searching for an answer for about an hour now, and I really need some help. Any help would be greatly appreciated.

    Thanks, Jon_d2.
     
  3. Unread #2 - Feb 20, 2009 at 6:36 PM
  4. cp
    Joined:
    Jan 30, 2007
    Posts:
    3,278
    Referrals:
    6
    Sythe Gold:
    0

    cp an cat
    Banned

    Help: GE Price Grabber

    You can use regular expressions, but you don't need to - there is a simpler way.

    Look into the split() function.

    Let's say the source of our page was this:
    Code:
    <table>
    <tr><td>Market Price</td><td>9999 GP</td></tr>
    <tr><td>Other Price</td><td>2192 GP</td></tr>
    </table>
    
    If we wanted the Market Price, we would do something similar to this:
    PHP:
    <?PHP
    // Let's assume that $page contains our data

    // Following line leaves $marketPrice with an array of everything
    // BEFORE AND AFTER the first argument in the split() function.
    $marketPrice split("<tr><td>Market Price</td><td>"$page);

    // Following line leaves  us with everything AFTER the first 
    // argument as seen in the previous part
    $marketPrice $marketPrice[1];

    // Now we have everything after the part we split it by. 
    // Now we want to isolate the price.
    $marketPrice split(" GP</td></tr>"$marketPrice);
    $marketPrice $marketPrice[0];

    echo 
    $marketPrice// You will see "9999" as output. 
    ?>
     
< [HELP] What next? | Adding a CSS to SMF 1.1.8? >

Users viewing this thread
1 guest


 
 
Adblock breaks this site