Results 1 to 2 of 2

Thread: Grabbing information from a website

Hybrid View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2007
    Posts
    70

    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> 
               
               
               &nbsp;&nbsp;<a href="ratings" class="tn15more">1,047 votes</a>&nbsp;&raquo;
            
            
          </div>
    Can someone forward me in the correct direction on what I need to do this?

  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Grabbing information from a website

    vb Code:
    1. Sub GetRating()
    2.         Dim wc As New Net.WebClient
    3.         ' Add this if you're using a proxy for Internet connection
    4.         ' wc.Proxy = Net.WebRequest.DefaultWebProxy
    5.         ' Add this if your web-proxy needs authentication
    6.         ' wc.Proxy.Credentials = New Net.NetworkCredential("username", "password")
    7.  
    8.         Dim htmlcode As String = ""
    9.         Try
    10.             Using rd As New IO.StreamReader(wc.OpenRead("http://www.imdb.com/title/tt0435761/"))
    11.                 htmlcode = rd.ReadToEnd
    12.             End Using
    13.         Catch ex As Net.WebException
    14.             ' Web error (404, 401, 403, etc)
    15.         Catch ex As Exception
    16.             ' Other error
    17.         End Try
    18.  
    19.         Dim rating As String = ""
    20.  
    21.         If Not htmlcode = "" Then
    22.  
    23.             Dim pattern As String = "<div class=""starbar-meta"">"
    24.             Dim p As Integer = htmlcode.IndexOf(pattern)
    25.  
    26.             p += pattern.Length
    27.  
    28.             rating = htmlcode.Substring(p, htmlcode.IndexOf("</b>", p) - p)
    29.             rating = rating.Replace("<b>", String.Empty).Trim
    30.             MsgBox(rating)
    31.         Else
    32.             MsgBox("No data to display")
    33.         End If
    34. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width