c#應用htmlagilitypack解析html格局字符串。本站提示廣大學習愛好者:(c#應用htmlagilitypack解析html格局字符串)文章只能為提供參考,不一定能成為您想要的結果。以下是c#應用htmlagilitypack解析html格局字符串正文
應用辦法:
1.援用HtmlAgilityPack.dll文件
2.援用定名空間:
using HtmlAgilityPack;
3.挪用
static void Main(string[] args)
{
string html = GetHtml("http://www.jb51.net");
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);
HtmlNode node = doc.DocumentNode;
HtmlNode div = node.SelectNodes("//table[@class='dataintable']")[0];
Console.WriteLine(div.InnerHtml);
Console.Read();
}
static string GetHtml(string url)
{
WebRequest request = WebRequest.Create(url);
WebResponse res = request.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
string html = sr.ReadToEnd();
sr.Close();
res.Close();
return html;
}