- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 WebBrowser
类,但它当然不起作用。
我的代码:
WebBrowser browser = new WebBrowser();
browser.Navigate("http://www.google.com");
while(browser.DocumentText == "")
{
continue;
}
string html = browser.DocumentText;
browser.DocumentText
始终是 ""
。为什么?
最佳答案
您应该使用 DocumentCompleted
事件,如果您没有 WebForms 应用程序,则可能还需要 ApplicationContext。
static class Program
{
[STAThread]
static void Main()
{
Context ctx = new Context();
Application.Run(ctx);
// ctx.Html; -- your html
}
}
class Context : ApplicationContext
{
public string Html { get; set; }
public Context()
{
WebBrowser browser = new WebBrowser();
browser.AllowNavigation = true;
browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted);
browser.Navigate("http://www.google.com");
}
void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
Html = ((WebBrowser)sender).DocumentText;
this.ExitThread();
}
}
关于c# - WebBrowser - 空 DocumentText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8526161/
我有一个 Windows 窗体,它有一个 WebBrowser 控件名称 formWebBrowser。我正在使用另一个名为 newThreadBrowser 的 WebBrowser 实例创建一个新
我正在尝试使用 WebBrowser 类,但它当然不起作用。 我的代码: WebBrowser browser = new WebBrowser(); browser.Navigate("http:/
在我的 vb.net 程序中,我使用网络浏览器向用户显示 HTML 预览。我之前通过服务器获取 HTML,然后在异步线程上返回并引发事件以使用我返回的 HTML 字符串填充 WebBrowser.Do
有没有一种方法可以在不读取文件的情况下将 WebBrowser.DocumentText 设置为文件,将其内容设置为字符串变量,然后将 WebBrowser.DocumentText 设置为该字符串变
我正在使用 WebBrowser 控件并显示文本,但它没有使用链接的 css,它只是显示为纯文本。我像这样填充它 webBrowser1.DocumentText = some_text; 在 som
我不明白为什么这行简单的代码行不通: // Bulding tree var declaration = new XDeclaration("1.0", "UTF-8", "yes"); var ro
或者是否有人知道可以替代的控件? 向嵌入了数据库中的图像和其他资源的 WebBrowser 控件提供内容会很方便,而无需依赖于托管在 Web 服务器上的这些资源或在本地文件系统上创建临时文件。 Mht
标题基本上就是这样说的,我有一个带有 TreeView 和一个网络浏览器控件以及三个按钮的 from。我希望后退按钮从 myresources 加载以前查看过的 html 文件,对于 forward
是的,我使用的 webBrowser 控件在 IE8 中工作正常,但在 IE9 中不行。似乎将 HTMLDocument 从 DesignMode =“On”设置为 DesignMode =“Off”
是的,我使用的 webBrowser 控件在 IE8 中工作正常,但在 IE9 中不行。似乎将 HTMLDocument 从 DesignMode =“On”设置为 DesignMode =“Off”
我是一名优秀的程序员,十分优秀!