PDA

View Full Version : [vb.net] Money Tree Items Extraction



DarkByte
07-01-2012, 07:58 AM
In a class:




Public Class moneytree


Public Sub RefreshItemList(ByVal sourestr As String, ByVal extracttolist As List(Of MoneyTreeItems))
'Extracts the take donation urls and item name in 1 swoop
Dim Temp As Long, temp1 As Long, temp2 As Long, temp3 As Long, temp4 As Long, temp5 As Long, temp6 As Long, temp7 As Long 'Trash vars

temp1 = 1 'Add a default start position
sourestr = Replace(sourestr, Chr(34), "'") 'Remove Quotes from source code and switch them to commas

If InStr(sourestr, "takedonation_new") < 1 Then 'Does the phrase takedonation_new appear in the source , if not there no items so we might aswell save ticks an quit
Exit Sub
End If


Do While InStr(temp1, sourestr, "</A><BR><B>", vbTextCompare) <> 0 'Only search while there is new items available after the last searched item
Dim tempitem As New MoneyTreeItems 'A single holder for the current item
tempitem.itemname = ""
tempitem.takeurl = ""
tempitem.isneopoints = False
Temp = InStr(temp1, sourestr, "</A><BR><B>", vbTextCompare) + Len("</A><BR><B>") 'Search the current html dot the position of "</A><BR><B>" , with a start location of temp1 (last found item)
temp2 = InStr(Temp, sourestr, "</B><BR>(", vbTextCompare) 'position of end string using location found in above line of code as a start position
temp3 = temp2 - Temp 'Start position of the string to be extracted
temp1 = temp2 + 1 'End position of the string to be extracted
Dim currentitemname As String = Mid$(sourestr, Temp, temp3) 'Current item name extracted
temp4 = InStrRev(sourestr, "takedonation_new.phtml?donation_id=", Temp) 'Search backwards from the last beggining position
temp5 = InStr(temp4, sourestr, "'>", vbTextCompare)
temp6 = temp5 - temp4 'End position of the string to be extracted
Dim currentitemurl As String = Mid$(sourestr, temp4, temp6) 'Current item name extracted


Dim itemnamelen As Integer = Len(currentitemname) 'Get length of the current items name
Dim tempstr As String = Mid(currentitemname, itemnamelen - 2, 3) 'Extract the last 3 letter of the current items name
If tempstr <> " NP" Then 'If this item is a "neopoints item" the last 3 letters will be " NP"

tempitem.isneopoints = True

Else
tempitem.isneopoints = False

End If
tempitem.takeurl = "[Only registered and activated users can see links]" & currentitemurl

tempitem.itemname = currentitemname 'Create new item
extracttolist.Add(tempitem) 'Add item to our list



Loop





End Sub

End Class

Public Class MoneyTreeItems

Public itemname As String
Public takeurl As String
Public isneopoints As Boolean

End Class





now in a button..


Dim strhtml As String

strhtml = mywrapper.Request("GET", "[Only registered and activated users can see links]", mywrapper.LastPage)
Dim moneytreeitems As New List(Of MoneyTreeItems) 'Create a new list of money tree items
MoneyTreehandler.RefreshItemList(strhtml, moneytreeitems) 'Refresh the list based on strhtmls source

For y As Integer = 0 To moneytreeitems.Count - 1 'Loop every item currently found on the money tree
MsgBox("Name = " & moneytreeitems(y).itemname & "Url= " & moneytreeitems(y).takeurl )
Next y

Zachafer
07-03-2012, 03:52 PM
raredaredevil

This is how OOP is done:
Public Class MoneyTreeItem

Public Sub New(ByVal ItemName As String, ByVal URL As String)
Me.Name = ItemName
Me.URL = URL
End Sub
Private _isNP As Boolean
Private _name, _url As String
Public Property Name() As String
Get
Return _name
End Get
Private Set(ByVal value As String)
_name = value
Try
IsNP = value.Substring(value.Length - 3) = " NP"
Catch
IsNP = False
End Try
End Set
End Property

Public Property URL() As String
Get
Return _url
End Get
Private Set(ByVal value As String)
_url = value
End Set
End Property

Public Property IsNP() As String
Get
Return _isNP
End Get
Private Set(ByVal value As String)
_isNP = value
End Set
End Property

Public Shared Function ExtractItems(ByVal sourcestr As String) As List(Of MoneyTreeItem)
Dim List As List(Of MoneyTreeItem) = New List(Of MoneyTreeItem)
'code to extract items goes in here
'add the extracted items to List via List.Add(New MoneyTreeItem(Name, URL))
Return List
End Function
End Class

DarkByte
07-03-2012, 06:21 PM
raredaredevil

This is how OOP is done:
Public Class MoneyTreeItem

Public Sub New(ByVal ItemName As String, ByVal URL As String)
Me.Name = ItemName
Me.URL = URL
End Sub
Private _isNP As Boolean
Private _name, _url As String
Public Property Name() As String
Get
Return _name
End Get
Private Set(ByVal value As String)
_name = value
Try
IsNP = value.Substring(value.Length - 3) = " NP"
Catch
IsNP = False
End Try
End Set
End Property

Public Property URL() As String
Get
Return _url
End Get
Private Set(ByVal value As String)
_url = value
End Set
End Property

Public Property IsNP() As String
Get
Return _isNP
End Get
Private Set(ByVal value As String)
_isNP = value
End Set
End Property

Public Shared Function ExtractItems(ByVal sourcestr As String) As List(Of MoneyTreeItem)
Dim List As List(Of MoneyTreeItem) = New List(Of MoneyTreeItem)
'code to extract items goes in here
'add the extracted items to List via List.Add(New MoneyTreeItem(Name, URL))
Return List
End Function
End Class



Thanks for this , I looked up some YouTube clips on it yesterday too I really like this style of programming working in adapting my style to it .