//引用 Microsoft HTML Object Library //引用 Microsoft 浏览器 //这个是重网站上取(需要等一会) private void button1_Click(object sender, System.EventArgs e) { axWebBrowser1.Navigate("Http://www.csdn.net"); button1.Enabled=false; while (axWebBrowser1.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE) { //WebBrowser1 读取是异步的 Application.DoEvents(); System.Threading.Thread.Sleep(10);
} mshtml.IHTMLDocument2 doc = axWebBrowser1.Document as mshtml.IHTMLDocument2; if (doc !=null) { if (doc.body!=null) { string s = doc.body.innerText; if (s!=null && s.Length >0) { MessageBox.Show(s);
Regex.Replace(strValue,@"<[^<>]*>","");
//引用 Microsoft 浏览器
//这个是重网站上取(需要等一会)
private void button1_Click(object sender, System.EventArgs e)
{
axWebBrowser1.Navigate("Http://www.csdn.net");
button1.Enabled=false;
while (axWebBrowser1.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
{
//WebBrowser1 读取是异步的
Application.DoEvents();
System.Threading.Thread.Sleep(10);
}
mshtml.IHTMLDocument2 doc = axWebBrowser1.Document as mshtml.IHTMLDocument2;
if (doc !=null)
{
if (doc.body!=null)
{
string s = doc.body.innerText;
if (s!=null && s.Length >0)
{
MessageBox.Show(s);
}
}
}
button1.Enabled=true;
}
//下面的是重你自己已经有的 html 里取
private static string HtmlText(AxSHDocVw.AxWebBrowser Wb,string HtmlStr)
{
Wb.Navigate("about:blank");
while (Wb.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
{
Application.DoEvents();
}
Application.DoEvents();
mshtml.IHTMLDocument2 doc = Wb.Document as mshtml.IHTMLDocument2;
doc.close();
doc.write(HtmlStr);
return doc.body.innerText;
}
private void button2_Click(object sender, System.EventArgs e)
{
MessageBox.Show(HtmlText(axWebBrowser1,"<Html>哈哈哈哈<html>"));
}