HtmlAgilityPack: Get whole HTML document as string

孤者浪人 提交于 2019-11-30 07:17:36

问题


Does HtmlAgilityPack have the ability to return the whole HTML markup from an HtmlDocument object as a string?


回答1:


Sure, you can do like this:

HtmlDocument doc = new HtmlDocument();
// call one of the doc.LoadXXX() functions
Console.WriteLine(doc.DocumentNode.OuterHtml);

OuterHtml contains the whole html.




回答2:


You can create WebRequest passing Url and Get webResponse . Get ResponseStream from WebResponse and read it into a String.

string result = string.Empty;

WebRequest req = WebRequest.Create(Url);
WebResponse res= wrq.GetResponse();    
StreamReader reader = new StreamReader(res.GetResponseStream());
result = reader.ReadToEnd();    
reader.Close();
res.Close();

Hope this helps.



来源:https://stackoverflow.com/questions/5183385/htmlagilitypack-get-whole-html-document-as-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!