Exemplo n.º 1
0
        private static List <Work> AdaptWorks(IEnumerable <HtmlNode> nodes)
        {
            var works = new List <Work>();

            foreach (var htmlNode in nodes)
            {
                try
                {
                    var titleAuthor = htmlNode.QuerySelectorAll("div.header h4.heading a").ToList();
                    var words       = htmlNode.QuerySelector("dl.stats dd.words");
                    var kudos       = htmlNode.QuerySelector("dl.stats dd.kudos a");
                    var comments    = htmlNode.QuerySelector("dl.stats dd.comments a");
                    works.Add(new Work
                    {
                        WorkId = titleAuthor.ElementAtOrDefault(0) is null
                            ? 0
                            : int.Parse(Sanitizer.IdSanitizer(titleAuthor[0].Attributes["href"].Value)),
                        Title        = titleAuthor.ElementAtOrDefault(0) is null ? "" : titleAuthor[0].InnerText,
                        Link         = Ao3Routes.BaseUrl + titleAuthor.ElementAtOrDefault(0)?.Attributes["href"].Value,
                        Author       = titleAuthor.ElementAtOrDefault(1) is null ? "" : titleAuthor[1].InnerText,
                        Fandom       = Sanitizer.ListToListSanitizer(htmlNode.QuerySelectorAll("div.header h5.fandoms a").Select(fandoms => fandoms.InnerText).ToList()),
                        Summary      = Sanitizer.ListToStringSanitizer(htmlNode.QuerySelectorAll("blockquote.summary p").Select(sum => sum.InnerText).ToList()),
                        Language     = htmlNode.QuerySelector("dl.stats dd.language").InnerText ?? "",
                        Tags         = Sanitizer.ListToListSanitizer(htmlNode.QuerySelectorAll("ul.tags li").Select(el => el.QuerySelector("a").InnerText).ToList()),
                        RequiredTags = Sanitizer.ListToListSanitizer(htmlNode.QuerySelectorAll("div.header ul.required-tags li a").Select(tag => tag.InnerText).ToList()),
                        Words        = int.Parse(words is null ? "0" : Sanitizer.NumberSanitizer(words.InnerText)),
                        Comments     = int.Parse(comments is null ? "0" : Sanitizer.NumberSanitizer(comments.InnerText)),
                        Kudos        = int.Parse(kudos is null ? "0" : Sanitizer.NumberSanitizer(kudos.InnerText)),
                    });
                }