0

I want to extract specific values from a website that shows me progress within a game, to show them in a vb.net application for easier access. The HTML code I would like to get the data from is:

<div id="freemodeRank" class="page-section clearfix">
    <div class="rankHex right-grad bronze">
        <h3 style="font-size:54px">225</h3>
        <p style="text-align:center;"></p>
    </div>
    <div class="rankXP">
        <div class="clearfix">
            <h3 class="left">5.6M<span> RP</span></h3>
        </div>
        <div class="rankBar">   
            <h4>Play Time: 58d 4h 23m</h4>

The data I would like to get from this code are:

"225", "5.6M" and "Play Time: 58d 4h 23m"

Any help would be great.

Jordan Lee
  • 13
  • 4

2 Answers2

0

You can use a GetBetween function to help you with this.

Public Function GetBetween(ByRef sSearch As String, ByRef sStart As String, ByRef sStop As String, _
                                                Optional ByRef lSearch As Long = 1) As String
    lSearch = InStr(lSearch, sSearch, sStart)
    If lSearch > 0 Then
        lSearch = lSearch + Len(sStart)
        Dim lTemp As Long
        lTemp = InStr(lSearch, sSearch, sStop)
        If lTemp > lSearch Then
            GetBetween = Mid$(sSearch, lSearch, lTemp - lSearch)
        End If
    End If
End Function

Source: http://www.devx.com/tips/Tip/40934

You can call it like this

'Assuming htmlData is the variable where your html string is stored
Dim rpAmount As String = GetBetween(htmlData, "<h3 class=""left"">", "<span> RP</span></h3>")

The same applies the rest of the values you want to scrape

ebildude123
  • 188
  • 7
  • Thanks for the help. One issue I have is "InStr" has an error: "Returns an integer specifying the start position of the first occurrence of one string within another.", how do I fix that? – Jordan Lee Jul 17 '16 at 04:22
  • What's the error message? You posted a description of what InStr does. Also, can you post how you are calling this function? (the line of code) – ebildude123 Jul 17 '16 at 04:33
  • @ebildude123 - `vb6`? – Fabio Jul 17 '16 at 08:19
0

HTML is Xml. Use XDocument class for getting your data. XDocument Class

Dim html As String = "<html><div id=""freemodeRank""><h3>255</h3></div></html>"

Dim document As XDocument = XDocument.Parse(html)
Dim value As String = document.Root...
                               <div>.
                               Where(Function(div) div.@id.Value.Equals("freemodeRank")).
                               <h3>.
                               First().
                               Value

XML Axis Properties (Visual Basic)

LINQ to XML without axis properties

Dim value As String = 
    document.Root.
             Descendants("div").
             Where(Function(div) div.Attribute("id").Value.Equals("freemodeRank")).
             Element("h3").
             Value

Overview of LINQ to XML in Visual Basic

Fabio
  • 31,528
  • 4
  • 33
  • 72