当前位置: 编程技术>.net/c#/asp.net
c#使用htmlagilitypack解析html格式字符串
来源: 互联网 发布时间:2014-10-29
本文导语: 使用方法: 1.引用HtmlAgilityPack.dll文件 2.引用命名空间: 代码如下:using HtmlAgilityPack; 3.调用 代码如下: static void Main(string[] args) { string html = GetHtml("http://www."); HtmlDocument doc = new HtmlDo...
使用方法:
1.引用HtmlAgilityPack.dll文件
2.引用命名空间:
代码如下:
using HtmlAgilityPack;
3.调用
代码如下:
static void Main(string[] args)
{
string html = GetHtml("http://www.");
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;
}
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。