如何抓取 JavaScript WebBrowser 更新的内容 [英] How to grab the Contents Which updated by JavaScript WebBrowser

查看:30
本文介绍了如何抓取 JavaScript WebBrowser 更新的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void button1_Click(object sender, EventArgs e)
{
    webBrowser1.Navigate(textBox1.Text);
}

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    WebBrowser web = (WebBrowser)sender;
    richTextBox1.Text = web.DocumentText;
}

以上是示例代码.它给出当前打开的所有文本,如果内容被 JavaScript 更新,它可见但 Document.Text 不更新.

above is sample code. it's giving all Text of Current Open, if contents is updated by JavaScript, it visible but Document.Text not update.

请大家帮忙

推荐答案

我遇到了同样的问题.使用以下示例代码:

I had the same problem. Use the following sample code:

IHTMLDocument2 doc = webBrowser1.Document.DomDocument as IHTMLDocument2;
string content = doc.body.innerText;

另外,将 mshtml 添加到您项目的引用中(如果您不知道如何添加引用,只需 google 即可).

Also, add mshtml to the references of your project (if you dont know how to add the refernce, just google it).

实际上,无论何时使用此代码,doc 变量中的值都是网络浏览器内容的更新版本.

Actually, whenever you use this code, the value in the doc variable is the updated version of the contents of the webbrowser.

祝你好运

这篇关于如何抓取 JavaScript WebBrowser 更新的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆