none
Question about WebBrowser RRS feed

  • Question

  • Hey,

    I'm trying to get the text from a website using DocumentText from the WebBrowser but it doesn't exist for me.
    I use the following code:

    Dim wb as WebBrowser
    wb.Navigate(URL)

    But when I try to use wb.DocumentText it auto corrects me to wb.Document because DocumentText is not existing.
    I've used Visual Studio Community 2015 and 2017 but am getting the same result in both.

    Does someone know a solution to this?
    Thanks in advance

    Kind regards

    Thursday, July 27, 2017 5:45 PM

All replies

  • Hey,

    I'm trying to get the text from a website using DocumentText from the WebBrowser but it doesn't exist for me.
    I use the following code:

    Dim wb as WebBrowser
    wb.Navigate(URL)

    But when I try to use wb.DocumentText it auto corrects me to wb.Document because DocumentText is not existing.
    I've used Visual Studio Community 2015 and 2017 but am getting the same result in both.

    Does someone know a solution to this?
    Thanks in advance

    Kind regards

    This won't work for all sites, but it's worth a try:

    Imports System.Net
    Imports System.IO

        Private Function _
           GetTextFromURL(ByVal url As String, _
                          Optional ByVal timeoutMS As Integer = 500) As String
    
            Dim retVal As String = Nothing
    
            Try
                Dim request As WebRequest = WebRequest.Create(url)
                request.Timeout = timeoutMS
    
                Using response As HttpWebResponse = DirectCast(request.GetResponse, HttpWebResponse)
                    Using dataStream As Stream = response.GetResponseStream
                        Using reader As New StreamReader(dataStream)
                            Dim responseFromServer As String = reader.ReadToEnd()
                            retVal = responseFromServer
                        End Using
                    End Using
                End Using
    
            Catch ex As System.Net.WebException
                ' Intentionally empty: Be sure to test
                ' the return value.
    
            Catch ex As Exception
                MessageBox.Show(String.Format("An error occurred:{0}{0}{1}", _
                                              vbCrLf, ex.Message), _
                                              "Exception Thrown", _
                                              MessageBoxButtons.OK, _
                                              MessageBoxIcon.Warning)
            End Try
    
            Return retVal
    
        End Function


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, July 27, 2017 5:49 PM
  • Probably your program is a WPF one, where DocumentText is not available. (It is for Windows Forms). Then try the InnerHtml property: https://social.msdn.microsoft.com/Forums/vstudio/en-US/37c0422a-17a6-4ee0-9f3f-669bdafb0b9d.

    Thursday, July 27, 2017 7:16 PM
  • DocumentText is a property of  System.Windows.Forms.WebBrowser.  Is your app WPF?

    Lloyd Sheen

    Thursday, July 27, 2017 8:22 PM
  • Hi Deuce,

    Have you resolved your issue now? If not, please help us to confirm that your project is WPF or other? if it is WPF project , please ask your question in WPF forum for professional help.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=wpf

    Thanks for your understanding.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 31, 2017 8:43 AM
    Moderator
  •         private void Form2_Load(object sender, EventArgs e)
            {
                webBrowser1.Navigate("http://www.linyee.net");
            }
    
            private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                Debug.Print(webBrowser1.DocumentText);
            }
    

    use like this...

    use property DocumentText mast after DocumentCompleted event

    or use WebRequest 

    祝你好运~~

    Tuesday, August 1, 2017 3:40 AM