c#使用htmlagilitypack解析html格式字符串
使用方法:
1.引用HtmlAgilityPack.dll文件
2.引用命名空間:
using HtmlAgilityPack;
3.調(diào)用
static void Main(string[] args)
{
string html = GetHtml("http://www.dbjr.com.cn");
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);
HtmlNode node = doc.DocumentNode;
HtmlNode div = node.SelectNodes("http://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;
}
相關(guān)文章
C# JSON格式化轉(zhuǎn)換輔助類 ConvertJson
本文介紹使用C#原生代碼實現(xiàn) JSON格式化以及各種類型轉(zhuǎn)化JSON的輔助類,幫助開發(fā)人員快速開發(fā)。2016-04-04Visual Studio連接unity編輯器的實現(xiàn)步驟
unity編輯器中打開C#腳本的時候發(fā)現(xiàn)Visual Studio沒有連接unity編輯器,本文主要介紹了Visual Studio連接unity編輯器的實現(xiàn)步驟,感興趣的可以了解一下2023-11-11