web浏览器 - 空DocumentText [英] WebBrowser - empty DocumentText

查看:116
本文介绍了web浏览器 - 空DocumentText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用 web浏览器类,当然这是行不通的。

I'm trying to use WebBrowser class, but of course it doesn't work.

我的code:

WebBrowser browser = new WebBrowser();
browser.Navigate("http://www.google.com");

while(browser.DocumentText == "")
{
    continue;
}
string html = browser.DocumentText;

browser.DocumentText 总是。为什么呢?

推荐答案

web浏览器是不会做的工作,直到当前线程完成它的工作,如果你改变了它是这样的:

The WebBrowser isn't going to do it's job until the current thread finishes it's work, if you changed it to be something like this:

        WebBrowser browser = new WebBrowser();
        browser.Navigate("http://www.google.com");
        browser.Navigated += (s, e) =>
            {
                var html = browser.DocumentText;
            };

该变量将被设置。

The variable will be set.

但是,正如其他人所说,完成了文档是一个更好的事件重视,因为在那个时候,整个文档将完成(在适当的名字!)

But, as others have mentioned, the document completed is a better event to attach to, as at that time, the entire document will be completed (appropriate name!)

        WebBrowser browser = new WebBrowser();
        browser.Navigate("http://www.google.com");

        browser.DocumentCompleted += (s, e) =>
            {
                var html = browser.DocumentText;
                html.ToString();
            };

这篇关于web浏览器 - 空DocumentText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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