博客園缺評論 RSS,利用 .NET 3.5 SyndicationFeed + WebClient + 正則解析 HTML,快速構建個人評論訂閱工具。
CommentRss.ashx?url=...WebClient.DownloadString 獲取 HTMLSyndicationFeed 對象Rss20FeedFormatter 輸出 RSS 2.0 XMLpublic class CommentRss : IHttpHandler {
public void ProcessRequest(HttpContext context) {
string url = context.Request.QueryString["url"];
string html = new WebClient { Encoding = Encoding.UTF8 }.DownloadString(url);
var feed = ParseHtmlToFeed(url, html); // 正則解析
context.Response.ContentType = "text/xml";
new Rss20FeedFormatter(feed).WriteTo(XmlWriter.Create(context.Response.Output));
}
// ParseHtmlToFeed 使用 Regex 匹配評論列表結構
}
System.ServiceModel.Syndication 命名空間原生支持 RSS/Atom