Results 1 to 3 of 3

Thread: Get Text From Webpage Help

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2018

    Get Text From Webpage Help

    Hello I was just wondering if on a webpage the html code was this

    How would I get the number 743 and put it into a text box keeping in mind this number changes every refresh?

    BTW: I'm new to the forum so if I did something wrong with the thread or anything like that please tell me

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    South Louisiana

    Re: Get Text From Webpage Help

    If you know when the page refreshes, then you could use a WebClient to download the data and get the information from your body tag like this:
    Using wc As Net.WebClient = New Net.WebClient()
        Dim webpage As String = wc.DownloadString("www.my_website.com")
        Dim starting_index As Integer = webpage.IndexOf("<body>")
        Dim contents_length As Integer = webpage.IndexOf("</body>") - starting_index
        Dim value As String = webpage.Substring(starting_index, contents_length)
        'value = 743
    End Using
    But again, this assumes that you know when the page will refresh. If you don't know when the page will refresh and you need to rely on a browser, then create a WebBrowser control and in the DocumentCompleted event, check if the URL equals your website URL and if so then grab the value from the <body> tag:
    Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        If WebBrowser1.Url = New Uri("www.my_website.com") Then
            Dim value As String = WebBrowser1.Document.Body.InnerText
            'Value = 743
        End If
    End Sub

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002

    Re: Get Text From Webpage Help

    If the site is refreshing on its own, then there is a fair chance that whoever created the site also created some other tools such as an API. If they have an API, then use the API, as that will ultimately make your life a whole lot easier.
    My usual boring signature: Nothing

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