本文介绍了将HtmlDocument.DomDocument转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将HtmlDocument.DomDocument转换为字符串?

How to convert HtmlDocument.DomDocument to string?

推荐答案

这个例子有点复杂,但假设你有使用称为 webBrowser1 的WebBrowser控件, Form1 的形式,变量内容将包含形成文档的标记:

This example is a bit convoluted, but, assuming you have a form called Form1, with a WebBrowser control called webBrowser1, the variable content will contain the markup that forms the document:

private void Form1_Load(object sender, EventArgs e)
{
    webBrowser1.Url = new Uri(@"http://www.robertwray.co.uk/");          
}

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    var document = webBrowser1.Document;
    var documentAsIHtmlDocument3 = (mshtml.IHTMLDocument3)document.DomDocument;

    var content = documentAsIHtmlDocument3.documentElement.innerHTML;
}

HtmlDocument.DomDocument webBrowser1_DocumentCompleted 事件处理程序中。

注意: mshtml 是通过向Microsoft HTML对象库(aka:mshtml.dll)添加COM引用获得的。

Note: mshtml is obtained by adding a COM reference to 'Microsoft HTML Object Library` (aka: mshtml.dll)

这篇关于将HtmlDocument.DomDocument转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 01:09