解析 WEB 中所有 URL 的简单牛B代码,先保存起来,方式将来找不到了
2011-11-22 16:48 通用C#系统架构 阅读(2166) 评论(5) 编辑 收藏 举报using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using Ivony.Fluent;
using Ivony.Web.Html;
using Ivony.Web.Html.Parser;
using Ivony.Web.Html.HtmlAgilityPackAdaptor;
using HtmlAgilityPack;
namespace Html解析
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var client = new WebClient();
var html = client.DownloadString("http://www.cnblogs.com/");
var parser = new JumonyParser();
var document = parser.Parse(html);
var links = document.Find("a[href]");
var baseUrl = new Uri("http://www.cnblogs.com");
var data = from hyperLink in links
let url = new Uri(baseUrl, hyperLink.Attribute("href").Value())
orderby url.AbsoluteUri
select new
{
Url = url.AbsoluteUri,
IsLinkingOut = !url.Host.EndsWith("cnblogs.com"),
Target = hyperLink.Attribute("target").Value() ?? "_self"
};
GridView1.DataSource = data;
GridView1.DataBind();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using Ivony.Fluent;
using Ivony.Web.Html;
using Ivony.Web.Html.Parser;
using Ivony.Web.Html.HtmlAgilityPackAdaptor;
using HtmlAgilityPack;
namespace Html解析
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var client = new WebClient();
var html = client.DownloadString("http://www.cnblogs.com/");
var parser = new JumonyParser();
var document = parser.Parse(html);
var links = document.Find("a[href]");
var baseUrl = new Uri("http://www.cnblogs.com");
var data = from hyperLink in links
let url = new Uri(baseUrl, hyperLink.Attribute("href").Value())
orderby url.AbsoluteUri
select new
{
Url = url.AbsoluteUri,
IsLinkingOut = !url.Host.EndsWith("cnblogs.com"),
Target = hyperLink.Attribute("target").Value() ?? "_self"
};
GridView1.DataSource = data;
GridView1.DataBind();
}
}
}
将权限管理、工作流管理做到我能力的极致,一个人只能做好那么很少的几件事情。