using System; using System.Windows.Forms; namespace WebBrowserExample { public partial class Form1 : Form { public Form1() { InitializeComponent(); webBrowser1.DocumentCompleted += WebBrowser1_DocumentCompleted; webBrowser1.Navigate("https://your-target-url.com"); } private void WebBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { // 確保網頁已經加載完成 if (webBrowser1.ReadyState == WebBrowserReadyState.Complete) { // 獲取 __VIEWSTATE var viewState = webBrowser1.Document.GetElementById("__VIEWSTATE"); if (viewState != null) { string viewStateValue = viewState.GetAttribute("value"); MessageBox.Show("VIEWSTATE: " + viewStateValue); } else { MessageBox.Show("__VIEWSTATE 元素未找到。"); } } } } }