Grabbing information from a website
Hello
I am trying to grab a small piece of information from imdb.
Using Toy Story 3 at this link: http://www.imdb.com/title/tt0435761/
It currently has a rating of 9.4. Now what I am trying to do is grab that 9.4/10. It is within the following html code.
Code:
<div class="starbar-meta">
<b>9.4/10</b>
<a href="ratings" class="tn15more">1,047 votes</a> »
</div>
Can someone forward me in the correct direction on what I need to do this?
Re: Grabbing information from a website
vb Code:
Sub GetRating()
Dim wc As New Net.WebClient
' Add this if you're using a proxy for Internet connection
' wc.Proxy = Net.WebRequest.DefaultWebProxy
' Add this if your web-proxy needs authentication
' wc.Proxy.Credentials = New Net.NetworkCredential("username", "password")
Dim htmlcode As String = ""
Try
Using rd As New IO.StreamReader(wc.OpenRead("http://www.imdb.com/title/tt0435761/"))
htmlcode = rd.ReadToEnd
End Using
Catch ex As Net.WebException
' Web error (404, 401, 403, etc)
Catch ex As Exception
' Other error
End Try
Dim rating As String = ""
If Not htmlcode = "" Then
Dim pattern As String = "<div class=""starbar-meta"">"
Dim p As Integer = htmlcode.IndexOf(pattern)
p += pattern.Length
rating = htmlcode.Substring(p, htmlcode.IndexOf("</b>", p) - p)
rating = rating.Replace("<b>", String.Empty).Trim
MsgBox(rating)
Else
MsgBox("No data to display")
End If
End Sub