如何使用htmlagilitypack抓取xml文件

本文关键字:xml 文件 抓取 htmlagilitypack 何使用 | 更新日期: 2023-09-27 18:22:25

我需要从http://feeds.feedburner.com/Torrentfreak以获取其链接和描述。

我用了这个代码:

    var webGet = new HtmlWeb();
                var document = webGet.Load("http://feeds.feedburner.com/TechCrunch");
    var TechCrunch = from info in document.DocumentNode.SelectNodes("//channel")
                                 from link in info.SelectNodes("//guid[@isPermaLink='false']")
                                 from content in info.SelectNodes("//description")
     select new
                                 {
                                     LinkURL = info.InnerText,
                                     Content = content.InnerText,
                                 };
lvLinks.DataSource = TechCrunch;
            lvLinks.DataBind(); 

我已经在列表视图控件中使用了这个来显示在asp.net页面上。使用

<%# Eval("LinkURL") %>  -  <%# Eval("Text") %> 

但其显示错误

值不能为null。参数名称:源

怎么了?是否可以使用HtmlAgilityPack抓取(获取)xml节点数据?请建议感谢

如何使用htmlagilitypack抓取xml文件

尝试使用RSS库而不是HtmlAgilityPack:

以下是一些可能对您有所帮助的链接:

  • http://www.rssdotnet.com/
  • http://www.yetanotherchris.me/home/2010/2/8/simplified-c-atom-and-rss-feed-parser.html

错误表明该值为null。所以有太可能的

select new
         {
                LinkURL = info.InnerText??string.Empty,
                Content = content.InnerText??string.Empty,
         };

或在aspx中。我认为字符串中应该是减号,如下所示:

<%# Eval("LinkURL")??string.Empty %>+"-"+<%# Eval("Text")??string.Empty %>