日期:2014-05-18  浏览次数:20977 次

C# 局部变量 WebBroswer 获取网页源代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

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

  private void Form1_Load(object sender, EventArgs e)
  {
  WebBrowser wb = new WebBrowser();

  wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);

  wb.Navigate("http://www.g.cn");
  }

  void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
  {
  //我想在这里获得wb打开的网页的源代码,请问应该怎么做
  }
  }
}


------解决方案--------------------
用如下代码就可了
C# code

WebBrowser browser = sender as WebBrowser;
MessageBox.Show(browser.DocumentText);