Exemplo n.º 1
0
        /// <summary>
        /// 解析插件列表页插件项目
        /// </summary>
        /// <param name="html"></param>
        /// <returns></returns>
        public static List <CurseListItem> PraseList(string html)
        {
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(html);
            var res = new List <CurseListItem>();
            HtmlNodeCollection lis = doc.DocumentNode.SelectNodes("//li[@class='project-list-item']");

            if (null == lis)
            {
                return(null);
            }
            if (lis.Count > 0)
            {
                for (int i = 0; i < lis.Count; i++)
                {
                    CurseListItem it = CurseListItem.TryPrase(lis[i].InnerHtml);
                    if (null != it)
                    {
                        it.isInstall = Settings.db.CheckInstalled(it.id);
                        res.Add(it);
                    }
                }
            }
            return(res);
        }
Exemplo n.º 2
0
 public static CurseListItem TryPrase(string html)
 {
     try
     {
         HtmlDocument doc = new HtmlDocument();
         doc.LoadHtml("<html>" + html.Replace("\n", "") + "</html>");
         HtmlNode      title = doc.DocumentNode.SelectSingleNode("//h2");
         CurseListItem it    = new CurseListItem();
         HtmlNode      thumb = doc.DocumentNode.SelectSingleNode("//img");
         it.title      = title.InnerText.Trim();
         it.thumbnails = thumb.GetAttributeValue("src", null);
         it.href       = title.ParentNode.GetAttributeValue("href", null);
         it.id         = it.href.Substring(it.href.LastIndexOf("/") + 1);
         HtmlNode meta = doc.DocumentNode.SelectSingleNode("//span[contains(@class,'count--download')]");
         it.download = meta.InnerText.Trim();
         string up = doc.DocumentNode.SelectSingleNode("//abbr").GetAttributeValue("data-epoch", null).Trim();
         if (!string.IsNullOrEmpty(up))
         {
             it.update = Curse.ConvertStringToDateTime(up).ToString();
         }
         it.description = doc.DocumentNode.SelectSingleNode("//div[@class='list-item__description']").InnerText.Trim();
         return(it);
     }
     catch
     {
         return(null);
     }
 }