Adblock breaks this site

Need help. Grand Exchange Item Pricer

Discussion in 'Programming General' started by Bernbomb, Sep 14, 2012.

  1. Bernbomb

    Bernbomb Newcomer

    Joined:
    Nov 30, 2010
    Posts:
    11
    Referrals:
    0
    Sythe Gold:
    0
    Need help. Grand Exchange Item Pricer

    All I want to do is change a "Label" into the price of any particular item(doesnt matter which one). Price needs to be grabbed off of the Grand Exchange though. Anyone help or can provide code?
     
  2. Blupig

    Blupig BEEF TOILET
    $5 USD Donor

    Joined:
    Nov 23, 2006
    Posts:
    7,145
    Referrals:
    16
    Sythe Gold:
    1,609
    Discord Unique ID:
    178533992981594112
    Valentine's Singing Competition Winner Member of the Month Winner MushyMuncher Gohan has AIDS Extreme Homosex World War 3 I'm LAAAAAAAME
    Off Topic Participant
    Need help. Grand Exchange Item Pricer

    Jagex offers a GE API now, google it. All you have to do is input the data you want into the API (item name or whatever) and grab the return. To grab the return you can use things like regex, split, and/or substrings.

    Parsing isn't exactly a beginner project, so do some research on it before you swan dive right into the middle of things.
     
  3. Bernbomb

    Bernbomb Newcomer

    Joined:
    Nov 30, 2010
    Posts:
    11
    Referrals:
    0
    Sythe Gold:
    0
    Need help. Grand Exchange Item Pricer

    im guessing no one wants to jsut give me the code :p
     
  4. iJava

    iJava .Previously known as RSGoldRush
    $200 USD Donor New

    Joined:
    Nov 21, 2011
    Posts:
    1,197
    Referrals:
    11
    Sythe Gold:
    485
    Discord Unique ID:
    220055593568829441
    Need help. Grand Exchange Item Pricer

    You won't learn by just getting the code, you need to research on how to split Strings.
     
  5. Bernbomb

    Bernbomb Newcomer

    Joined:
    Nov 30, 2010
    Posts:
    11
    Referrals:
    0
    Sythe Gold:
    0
    Need help. Grand Exchange Item Pricer

    I've researched just can't understand.
     
  6. JackIAm

    JackIAm Member

    Joined:
    Oct 21, 2012
    Posts:
    50
    Referrals:
    0
    Sythe Gold:
    0
    Need help. Grand Exchange Item Pricer

  7. Bernbomb

    Bernbomb Newcomer

    Joined:
    Nov 30, 2010
    Posts:
    11
    Referrals:
    0
    Sythe Gold:
    0
    Need help. Grand Exchange Item Pricer

    Alright this is the code I have come up with so far but im getting a "Indexoutofrange Exception" on a certain line (ill highlight below). Why? Whats the fix for this?

    Code:
    Imports System
    Imports System.IO
    Imports System.Net
    Public Class Form1
    
        Public Function GetBetween(ByRef strSource As String, ByRef strStart As String, ByRef strEnd As String, Optional ByRef startPos As Integer = 0) As String
            Dim iPos As Integer, iEnd As Integer, lenStart As Integer = strStart.Length
            Dim strResult As String
            strResult = String.Empty
            iPos = strSource.IndexOf(strStart, startPos)
            iEnd = strSource.IndexOf(strEnd, iPos + lenStart)
            If iPos <> -1 AndAlso iEnd <> -1 Then
                strResult = strSource.Substring(iPos + lenStart, iEnd - (iPos + lenStart))
            End If
            Return strResult
        End Function
    
        Public Function GetItemValue(ByRef ItemID As String)
    
    
            Dim Amount As String = 0
            Dim request As HttpWebRequest = HttpWebRequest.Create("http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=" & ItemID)
            Dim response As HttpWebResponse = request.GetResponse
            Dim sr As StreamReader = New StreamReader(response.GetResponseStream)
            Dim sourcecode As String = sr.ReadToEnd()
            Dim NewValue As String = GetBetween(sourcecode, "<th scope=" & Chr(34) & "row" & Chr(34) & ">Current guide price:</th>", "</tr>")
            NewValue = NewValue.Replace("<td>", "")
            NewValue = NewValue.Replace("</td>", "")
       [COLOR="Red"]   [B]  NewValue = Replace(NewValue, NewValue(0), vbNullString)[/B][/COLOR]
            Amount = NewValue
            Return Amount
         
    
        End Function
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim text As Integer
            text = GetItemValue("400")
            TextBox1.Text = text
        End Sub
    End Class
     
  8. hmm

    hmm Active Member

    Joined:
    Jan 21, 2007
    Posts:
    181
    Referrals:
    2
    Sythe Gold:
    5
    Need help. Grand Exchange Item Pricer

    Hi bernbomb, you're receiving this error because the ItemID "400" doesn't exist, see the following link with ItemID 400
    http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=400
    How to fix
    replace
    Code:
    text = GetItemValue("400")
    with
    Code:
    text = GetItemValue("1119")
    Explanation/random talking
    You can see if something is wrong with the sourcecode by browsing to the url in a webbrowser, or having a textbox show your variable "sourcecode" and browse through it there.
    alternatively if you do a simple "msgbox(newvalue)" after
    Code:
    Dim NewValue As String = GetBetween(sourcecode, "<th scope=" & Chr(34) & "row" & Chr(34) & ">Current guide price:</th>", "</tr>")
    to
    Code:
    Dim NewValue As String = GetBetween(sourcecode, "<th scope=" & Chr(34) & "row" & Chr(34) & ">Current guide price:</th>", "</tr>")
    msgbox(newvalue)
    and/or between the lines where you are modifying it, you can see the results(blank)

    How to get ItemID's
    Replace 400 with a proper ItemID, If you don't know how to get an ItemID, go to the Grand Exchange via webbrowser and search for an item, I'll search for "Steel platebody" and we'll use "Steel platebody" as the example.

    Code:
    Right-click the picture OR the text link and click one of the following.
    1. copy image location (Firefox)
    2. copy link location (Firefox)
    OR
    3. properties (Internet Explorer)
    4. copy shortcut (Internet Explorer)
    
    The links you should have gotten are:
    [url]http://services.runescape.com/m=itemdb_rs/Steel_arrow/viewitem.ws?obj=1119[/url]
    [url]http://services.runescape.com/m=itemdb_rs/3892_obj_sprite.gif?id=1119[/url]
    so we see that 1119 is our item ID, replace
    Code:
    text = GetItemValue("400")
    with
    Code:
    text = GetItemValue("1119")
    just like we did before.

    The ID's can be found in the page source too, of course. - And forgive me if you already knew how to get the numbers - i just assumed you don't.

    More random shiz
    I don't understand the purpose of the following lines though, getting the price works without it, and what is newvalue(0) supposed to represent because it has no value. :eek:
    Code:
     NewValue = Replace(NewValue, NewValue(0), vbNullString)
    You'll also notice that since your variable "text" is integer it will remove commas from "1,232" etc, to prevent this you'll want to make it a string instead.

    ------------------------------------------
    now I'm just being picky, this is how I'd do it, does essentially the same thing but with more simpler functions, webclient doesn't allow as much control as httpwebrequest - but that's fine because we won't be needing to edit the cookie, referrer, etc.
    Code:
    Public Function GetItemValue(ByRef ItemID As Integer)
            Dim Amount As String, webbrw As New Net.WebClient, sourcecode As String
            sourcecode = webbrw.DownloadString("http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=" & ItemID)
            Dim NewValue As String = Replace(Split(Split(sourcecode, "<th scope=" & Chr(34) & "row" & Chr(34) & ">Current guide price:</th>")(1), "</td>")(0), "<td>", "")
            'replaced the second splits "</tr>" with "</td>" for one less replace
    
            'if you really dont want every split/replace to be together then just uncomment this
            'Dim NewValue As String = Split(Split(sourcecode, "<th scope=" & Chr(34) & "row" & Chr(34) & ">Current guide price:</th>")(1), "</td>")(0)
            ' NewValue = Replace(NewValue, "<td>", "")
    
            Amount = NewValue
            Return Amount
        End Function
    
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim text As String
            text = GetItemValue("1119")
            TextBox1.Text = text
        End Sub
    


    So what you've posted has the potential to give information about one item, do you plan on customizing it a bit? IE; viewing other items, not just one set in code? Do you have an idea how to do it?
    I'll be posting a project very soon, depending on when i get time to finish it.
     
  9. Bernbomb

    Bernbomb Newcomer

    Joined:
    Nov 30, 2010
    Posts:
    11
    Referrals:
    0
    Sythe Gold:
    0
    Need help. Grand Exchange Item Pricer

    Im creating sort of like a spreadsheet that will calculate basically what the best gold per hour is available at any given day.

    The reason the 'text' variable is an integer is because I will need to multiply certain numbers of the variable that I recieve. If im not mistaken you can't do math with string (brain is tired).

    Thanks so much for your help btw.

    Rookie mistake that I overlooked but your right about the numbers. Im using a website (http://www.itemdb.biz/index.php) that gives the id numbers and for some reason I guess I put 400 instead of 200. I couldnt understand how it worked one minute and not the rest.

    hmm do you have msn or email ? in case I have a question for you?
     
  10. hmm

    hmm Active Member

    Joined:
    Jan 21, 2007
    Posts:
    181
    Referrals:
    2
    Sythe Gold:
    5
    Need help. Grand Exchange Item Pricer

    pm'd you on forum
     
  11. hackersrage

    hackersrage Newcomer

    Joined:
    Oct 25, 2012
    Posts:
    3
    Referrals:
    0
    Sythe Gold:
    0
    Need help. Grand Exchange Item Pricer

    Hmm.... no one seems to notice that you can get these results as JSON directly from the API >> Grand Exchange APIs

    Since VB.NET has access to parse json, you won't need to parse. Jagex also prefers that you use this API as it consumes less bandwidth, and gives you exactly what you are looking for.

    There are many libraries to work with JSON from .NET, for example Here is an OpenSource
     
  12. hmm

    hmm Active Member

    Joined:
    Jan 21, 2007
    Posts:
    181
    Referrals:
    2
    Sythe Gold:
    5
    Need help. Grand Exchange Item Pricer

    I know of the api, but afaik you can't search a single item with the api - fill me in if I'm wrong.
    Granted i could get it eventually through the categories, or finding an item id via another website, but i haven't bothered with that yet - laziness..
    finding an item id via runescapes GE page and then viewing it via API is no different than just viewing an item tbh, you're still viewing the item's page, again, unless theres some api for it that's undocumented.
     
< Programing/Coding websites | SELLing CVV, DUMPS,TRACK1&2,BANK TO BANK TRF & BANK LOGINS. WU >


 
 
Adblock breaks this site