Read HTML from a WebBrowser

3

I have a Form with a WebBrowser, two text boxes (1 and 2) and a button. In the text box 1 I enter a URL, press the button and execute:

private void button1_Click(object sender, EventArgs e)
{
    Uri myUri = new Uri(textBox1.Text);
    webBrowser1.Url = myUri;
    webBrowser1.Navigate(myUri);
}

The WebBrowser shows me the web page. Up there, right.

I want to take the HTML of the page and show it in TextBox2 and for that I do:

private void webBrowser1_DocumentCompleted(object sender,
    WebBrowserDocumentCompletedEventArgs e)
{
    textBox2.Text = webBrowser1.DocumentText;
}

But he does not show me anything. Can you help me?

    
asked by Samuel 04.02.2017 в 13:48
source

2 answers

1

You could try OuterHtml webBrowser1.Document.Body.OuterHtml;

    
answered by 04.02.2017 в 16:05
0

Your code as it works well. I tried it. Your problem should be the way you have defined your textBox2 . If you have not configured it to accept several lines of text, it will give you the impression that it is empty.

Change property Multiline from textBox2 to true , and you'll see that everything works fine.

    
answered by 04.02.2017 в 16:39