Adblock breaks this site

Help With Java, GE. - Robotz MTA Related.

Discussion in 'Programming General' started by Morphis, Aug 18, 2008.

  1. Morphis

    Morphis Apprentice
    Banned

    Joined:
    Aug 2, 2008
    Posts:
    734
    Referrals:
    0
    Sythe Gold:
    0
    Help With Java, GE. - Robotz MTA Related.

    Well I am working on something that involves Robotz Mage Training Arena Bot, and I need some help.

    I need help on how to extract the prices of items from the Grand Exchange Page on Runescape.
    For example, how could I get these values the min, market, and max of this item. - http://itemdb-rs.runescape.com/viewitem.ws?obj=9143

    Now you might ask what is the point in this? Well I want to make my program auto update the price by connecting to the items webpage and getting the min med and max values. Any help would be greatly appreciated.
     
  2. Weebs

    Weebs Newcomer

    Joined:
    Nov 5, 2005
    Posts:
    7
    Referrals:
    0
    Sythe Gold:
    0
    Help With Java, GE. - Robotz MTA Related.

    Are you looking to find the item price by it's ID, or by it's name?
     
  3. Morphis

    Morphis Apprentice
    Banned

    Joined:
    Aug 2, 2008
    Posts:
    734
    Referrals:
    0
    Sythe Gold:
    0
    Help With Java, GE. - Robotz MTA Related.

    I have the webpage I want to get the price from, i just need the program to be able to grab it.
     
  4. Weebs

    Weebs Newcomer

    Joined:
    Nov 5, 2005
    Posts:
    7
    Referrals:
    0
    Sythe Gold:
    0
    Help With Java, GE. - Robotz MTA Related.

    Here's a function that'll return the prices in a String array.

    Code:
    public static String[] getPrice(String urls) {
    	try {
    		String page = new String();
    		URL url = new URL(urls);
    		InputStream in = url.openStream();
    		BufferedInputStream bufIn = new BufferedInputStream(in);
    		
    		for(;;) {
    			int data = bufIn.read();
    			
    			if (data == -1)
    				break;
    			else
    				page += (char)data;
    		}
    		bufIn.close();
    		in.close();
    		String[] price = new String[3];
    		String[] array;
    		String splitter = "price:</b> ";
    			
    		array = page.split(splitter);
    		splitter = "</span>";
    		for (int i = 1; i <= 3; i++)
    				price[i - 1] = array[i].split(splitter)[0].replaceFirst("\n", "");
    		
    		return price;
    	} catch (MalformedURLException e) {
    		System.out.println(e.toString());
    		String error = "Unable to fetch price";
    		return new String[] { error, error, error };
    	} catch (IOException e) {
    		System.out.println(e.toString());
    		String error = "Unable to fetch price";
    		return new String[] { error, error, error };
    	}
    }
    An example of how to use this would be:
    Code:
    		String[] prices = getPrice("http://itemdb-rs.runescape.com/viewitem.ws?obj=9143");
    		for (int i = 0; i < 3; i++)
    			System.out.println(prices[i]);
    Output:
    Code:
    184
    193
    202
     
  5. Morphis

    Morphis Apprentice
    Banned

    Joined:
    Aug 2, 2008
    Posts:
    734
    Referrals:
    0
    Sythe Gold:
    0
    Help With Java, GE. - Robotz MTA Related.

    Wow thank you so much for this, I just needed a method but this, this is just amazing. You have no idea how much you helped me.
     
< Error in Visual Basic 2008 | Choose a combo, a picture shows >


 
 
Adblock breaks this site