コード例 #1
0
        private static SearchListData AnalyzeDocument(string HTMLCode, string link)
        {
            HtmlNode.ElementsFlags.Remove("option");

            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(HTMLCode);

            SearchListData list = new SearchListData();

            try
            {
                foreach (var animeNode in doc.DocumentNode.Descendants("div").First(x => x.GetAttributeValue("class", "") == "js-categories-seasonal js-block-list list").Descendants("tr").Skip(1))
                {
                    BaseAnimeEntry info = new BaseAnimeEntry()
                    {
                        ImageLink = new LinkInfo(animeNode.Descendants("td").ElementAt(0).Descendants("img").First().GetAttributeValue("src", "")),
                        Title     = HtmlEntity.DeEntitize(animeNode.Descendants("td").ElementAt(1).Descendants("a").First().InnerText),
                        AnimeLink = new LinkInfo(animeNode.Descendants("td").ElementAt(1).Descendants("a").First().GetAttributeValue("href", "")),
                        Synopsis  = HtmlEntity.DeEntitize(animeNode.Descendants("td").ElementAt(1).Descendants("div").First(x => x.GetAttributeValue("class", "") == "pt4").InnerText),
                        Type      = Utility.FixString(animeNode.Descendants("td").ElementAt(2).InnerText),
                        Episodes  = animeNode.Descendants("td").ElementAt(3).InnerText
                    };
                    float.TryParse(animeNode.Descendants("td").ElementAt(4).InnerText, out float score);
                    info.Score   = score;
                    info.Members = Utility.GetIntFromString(animeNode.Descendants("td").ElementAt(5).InnerText);
                    list.Animes.Add(info);
                }

                //TODO: Fix Pages
                if (doc.DocumentNode.Descendants().Any(x => x.GetAttributeValue("class", "") == "ac mt8"))
                {
                    int currOffset = 0;
                    if (link.Contains("&show="))
                    {
                        currOffset = Utility.GetIntFromString(link.Split('=').Last());
                    }
                    else
                    {
                        currOffset = 0;
                    }

                    link = link.Replace("&show=" + currOffset, "");

                    if (HtmlEntity.DeEntitize(doc.DocumentNode.Descendants().First(x => x.GetAttributeValue("class", "") == "ac mt8").InnerText).Contains("»"))
                    {
                        list.NextPageLink = new LinkInfo(link + "&show=" + (currOffset + 50));
                    }
                    if (HtmlEntity.DeEntitize(doc.DocumentNode.Descendants().First(x => x.GetAttributeValue("class", "") == "ac mt8").InnerText).Contains("«"))
                    {
                        list.PreviousPageLink = new LinkInfo(link + "&show=" + (currOffset - 50));
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + ex.StackTrace + "\n" + link);
            }

            return(list);
        }
コード例 #2
0
ファイル: Controller.cs プロジェクト: i3dprogrammer/MALParser
 public Controller(BaseAnimeEntry entry)
 {
     m_header = Header.Parse(entry.AnimeLink.Path);
 }