VB.Net Copy all text from WebBrowser

html html-agility-pack vb.net webbrowser-control

Question

I want to copy all visible text from WebBrowser.

Clipboard.SetText(WebBrowser1.Document.Body.InnerText)

This code is working, but it's also getting text between <div style="display:none"> and </div>, which i don't want (i want only text that is visible when i manually go to that website).

Accepted Answer

This works for me against google.com. This is mostly a translation of the c# version of the same question mentioned in the comments above.

    Dim text As String
    WebBrowser1.Document.ExecCommand("SelectAll", False, Nothing)
    WebBrowser1.Document.ExecCommand("Copy", False, Nothing)
    text = Clipboard.GetText()
    MessageBox.Show(text, "Text")


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why