C# WebBrowser Content Retrieval Guide

To obtain webpage content, you can utilize the Document property of the WebBrowser control. Here is a simple example:

using System;
using System.Windows.Forms;

namespace WebBrowserExample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            webBrowser1.Navigate("https://www.example.com");
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            // 获取网页内容
            string html = webBrowser1.DocumentText;
            Console.WriteLine(html);
        }
    }
}

In the example above, when the Form loads, we navigate to a URL. Then, once the webpage is fully loaded, we can retrieve the webpage content using the DocumentCompleted event. In this event handler, we use the DocumentText property to access the HTML content of the webpage.

bannerAds