dcsimg
Results 1 to 3 of 3
  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2018
    Posts
    3

    Get Text From Webpage Help

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

    <html>
    <head><>/head>
    <body>743</body>
    </html>
    How would I get the number 743 and put it into a text box keeping in mind this number changes every refresh?
    Thanks.

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

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,318

    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:
    Code:
    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:
    Code:
    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
    Location
    Idaho
    Posts
    32,029

    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
  •  



Featured


Click Here to Expand Forum to Full Width