Htmlagilitypack不转换<i>标签

时间:2015-10-01 08:42:44

标签: c# html asp.net html-agility-pack

我没有转换为HTMLAgilityPack标记。我怎样才能实现转型的价值?

这样,我想得到一个输出

  

YayınTarihi:13.09.2015--GüncellemeTarihi:18.09.2015

<ul class="DefaultAspxWebParcasi">
  <li>
    <a href="http://www.e-saglik.gov.tr/belge/1-44068/ozel-saglik-kurum-ve-kuruluslari-tarafindan-saglik-net-.html">
      <i> -Yayın Tarihi</i>
      : 18.09.2015 /
      <i> Güncellenme Tarihi</i>
      : 18.09.2015
  </li>
  <li>
    <a href="http://www.e-saglik.gov.tr/belge/1-42578/sagliknet-sistemi-2-ve-3-basamak-veri-gonderimi-ile-ilg-.html">
      <i> -Yayın Tarihi</i>
      : 13.08.2015 /
      <i> Güncellenme Tarihi</i>
      : 18.09.2015
  </li>

C#代码在这里。

WebClient wc = new WebClient();
            wc.Encoding = Encoding.UTF8;
            string data = wc.DownloadString(Link());
            HtmlAgilityPack.HtmlDocument doc = new  HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(data);
            HtmlAgilityPack.HtmlNodeCollection icCont2 = doc.DocumentNode.SelectNodes(@"//ul[@class='DefaultAspxWebParcasi']//li//a");

foreach (HtmlAgilityPack.HtmlNode item in icCont2)
                {
                    string iler = item.SelectSingleNode("//i").InnerHtml.ToString();

                    Console.WriteLine(iler);

                }

1 个答案:

答案 0 :(得分:1)

以下代码将生成-YayınTarihi:18.09.2015 /GüncellenmeTarihi:18.09.2015 。希望这会有所帮助

           var doc = new HtmlDocument();
            doc.LoadHtml(data);
            HtmlAgilityPack.HtmlNodeCollection icCont2 = doc.DocumentNode.SelectNodes(@"//ul[@class='DefaultAspxWebParcasi']//li//a");
            foreach (HtmlAgilityPack.HtmlNode item in icCont2)
            {
                Regex trimmer = new Regex(@"\s\s+");
                var iler = trimmer.Replace(item.InnerText, " ");
                Console.WriteLine(iler);
            }