HTML敏捷性包的HTMLDocument显示所有的HTML? [英] HTML Agility Pack HtmlDocument Show All Html?

查看:208
本文介绍了HTML敏捷性包的HTMLDocument显示所有的HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下列获得一个网页,正常工作

I am using the following to get a web page which works fine

    public static HtmlDocument GetWebPageFromUrl(string url)
    {
        var hw = new HtmlWeb();
        return hw.Load(url);
    }

但如何我吐了HTML的全部内容了从的HTMLDocument成字符串?

But how to I spit the entire contents of the HTML out from the HtmlDocument into a string?

我试过HtmlDocument.ToString(),但是这并没有给我的文档中的所有HTML?任何想法?

I tried HtmlDocument.ToString() but that doesn't give me all the HTML in the document? Any ideas?

推荐答案

DocumentNode.OuterHtml 包含了完整的HTML:

DocumentNode.OuterHtml contains the full html:

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.Load("sample.html");
string html = doc.DocumentNode.OuterHtml;

在您的例子:

public static string GetWebPageHtmlFromUrl(string url)
{
    var hw = new HtmlWeb();
    HtmlDocument doc = hw.Load(url);
    return doc.DocumentNode.OuterHtml;
}

这篇关于HTML敏捷性包的HTMLDocument显示所有的HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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