从字符串中加载而不是从文档/URL中加载

25
我刚刚发现了Html Agility Pack并尝试使用它,但遇到了一个问题。我在网上找不到任何相关的信息,所以来这里请教。

您知道如何从字符串中加载HTML而不是从文档/URL中加载吗?

谢谢。

3个回答

59

你尝试使用过 LoadHtml 吗?

string htmlString = 'Your html string here...';

HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
htmlDocument.LoadHtml(htmlString);

// Do whatever with htmlDocument here

3
我认为有一个函数可以做到这个,对吗?
HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml("<test>");

-1

这篇文章可能有点旧了,但我认为它会对其他人有所帮助。

        WebBrowser web_browser = new WebBrowser();
        web_browser.DocumentText = html_contents_as_string;

        do
        {
            Application.DoEvents();
        } while (web_browser.ReadyState != WebBrowserReadyState.Complete);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接