Ejemplo n.º 1
0
        /// <summary>
        ///     获取一个链接下的图标模型集合
        /// </summary>
        /// <param name="url"></param>
        /// <param name="cgKey"></param>
        /// <returns></returns>
        private static List <CardModel> GetCardPreviewModels(string url, int cgKey)
        {
            var race   = CardUtils.GetRace(cgKey);
            var rarity = CardUtils.GetRarity(cgKey);
            var web    = new HtmlWeb {
                OverrideEncoding = Encoding.GetEncoding("EUC-JP")
            };
            var frame = web.Load(url);
            var nodes =
                frame.DocumentNode.SelectNodes(@"//table")
                .First(x => x.Attributes["id"].Value.Equals("content_block_1"));
            var childNodes =
                nodes.SelectNodes(@"//a")
                .Where(x => (null != x.Attributes["href"]) && (3 == x.ChildNodes.Count))
                .ToList();

            return((from childNode in childNodes
                    let hrefUrl = childNode.Attributes["href"].Value
                                  let imageUrl = childNode.ChildNodes[0].Attributes["src"].Value
                                                 let name = childNode.ChildNodes[2].InnerText
                                                            select new CardModel
            {
                Md5 = Md5Utils.GetMd5(name),
                Name = name,
                IconUrl = imageUrl,
                IconStats = 0,
                HrefUrl = hrefUrl,
                ImagesUrl = string.Empty,
                ImagesStats = 0,
                Race = race,
                Rarity = rarity
            })
                   .ToList());
        }