Created
July 28, 2014 19:35
-
-
Save AlexArchive/8a8a154de1266dc26e96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Class GrandExchange | |
Public Structure GrandExchangeItem | |
#Region "Public Read-Only Properties" | |
Public ReadOnly Property ItemName As String | |
Get | |
Return privItemName | |
End Get | |
End Property | |
Public ReadOnly Property ItemPrice As String | |
Get | |
Return privItemPrice | |
End Get | |
End Property | |
Public ReadOnly Property ChangeToday As String | |
Get | |
Return privTodaysChange | |
End Get | |
End Property | |
Public ReadOnly Property MembersOnly As Boolean | |
Get | |
Return privMembers | |
End Get | |
End Property | |
Public ReadOnly Property ItemID As Integer | |
Get | |
Return privItemID | |
End Get | |
End Property | |
#End Region | |
#Region "Private Variables" | |
Private privItemName As String | |
Private privItemPrice As String | |
Private privTodaysChange As String | |
Private privMembers As Boolean | |
Private privItemID As Integer | |
#End Region | |
#Region "Methods" | |
Sub New(ByVal itemName As String, ByVal itemPrice As String, ByVal todaysChange As String, ByVal members As Boolean, ByVal itemID As Integer) | |
privItemName = itemName | |
privItemPrice = itemPrice | |
privTodaysChange = todaysChange | |
privMembers = members | |
privItemID = itemID | |
End Sub | |
#End Region | |
End Structure | |
Public Shared Function Search(ByVal searchQuery As String) As GrandExchangeItem() | |
Dim tempList As List(Of GrandExchangeItem) = New List(Of GrandExchangeItem) | |
Dim returnList As GrandExchangeItem() | |
Dim httpWebReq As Net.HttpWebRequest | |
Dim httpWebResp As Net.HttpWebResponse | |
Dim respStream As IO.Stream | |
Dim respReader As IO.StreamReader | |
Dim respSource As String | |
Dim pageIndex As Integer = 1 | |
Dim maxPageIndex As Integer | |
Dim tempSplit() As String | |
Do | |
httpWebReq = Net.HttpWebRequest.Create("http://services.runescape.com/m=itemdb_rs/results.ws?query=" & searchQuery & "&page=" & pageIndex) | |
httpWebResp = httpWebReq.GetResponse() | |
respStream = httpWebResp.GetResponseStream() | |
respReader = New IO.StreamReader(respStream) | |
respSource = respReader.ReadToEnd | |
respStream.Close() | |
If respSource.Contains("did not return any results") Then Throw New Exception("Invalid item name.") | |
tempSplit = Split(Split(Split(respSource, "<td class=""navmid"">")(1), "</td>")(0).ToLower, "page=") | |
maxPageIndex = tempSplit(tempSplit.Length - 1).Split("&")(0) | |
tempSplit = Split(Split(Split(respSource, "<tbody>")(1), "</tbody>")(0), "<tr") | |
For I = 1 To tempSplit.Length - 1 | |
Dim tempName As String | |
Dim tempID As String | |
Dim tempPrice As String | |
Dim tempChange As String | |
Dim tempMembers As Boolean | |
Dim tempLines() As String | |
tempLines = Split(tempSplit(I).Replace("<td>", String.Empty), "</td>") | |
tempName = tempLines(1).Split(">")(1).Split("<")(0).Trim | |
tempID = Split(tempLines(1), "obj=")(1).Split("""")(0) | |
tempPrice = tempLines(2).Split("<")(0).Trim | |
tempChange = tempLines(3).Split(">")(1).Split("<")(0).Trim | |
tempMembers = tempLines(4).Contains("star_free") | |
Dim tempGEItem As New GrandExchangeItem(tempName, tempPrice, tempChange, tempMembers, tempID) | |
tempList.Add(tempGEItem) | |
tempGEItem = Nothing | |
tempID = Nothing | |
tempName = Nothing | |
tempChange = Nothing | |
tempPrice = Nothing | |
tempMembers = Nothing | |
tempLines = Nothing | |
Next | |
pageIndex += 1 | |
Loop Until pageIndex > maxPageIndex | |
returnList = tempList.ToArray() | |
tempList = Nothing | |
httpWebReq = Nothing | |
httpWebResp = Nothing | |
respStream = Nothing | |
respReader = Nothing | |
respSource = Nothing | |
pageIndex = Nothing | |
maxPageIndex = Nothing | |
tempSplit = Nothing | |
Return returnList | |
End Function | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment