예제 #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)),
                    });
                }
예제 #2
0
 private static WorkChapter AdaptChapter(HtmlNode node)
 {
     var preface     = node.QuerySelector("div#workskin div.preface");
     var chapter     = node.QuerySelector("div#workskin div.chapter");
     var details     = node.QuerySelector("div.wrapper dl.work");
     var words       = details.QuerySelector("dd.stats dl.stats dd.words");
     var kudos       = details.QuerySelector("dd.stats dl.stats dd.kudos");
     var comments    = details.QuerySelector("dd.stats dl.stats dd.comments");
     var workChapter = new WorkChapter
     {
         ChapterTitle   = chapter.QuerySelector("div.chapter h3.title a")?.InnerText,
         ChapterSummary = Sanitizer.TextSanitizer(preface.QuerySelector("div.summary blockquote p")?.InnerText),
         ChapterNotes   = Sanitizer.TextSanitizer(chapter.QuerySelector("div.chapter div.notes p")?.InnerText),
         WorkDetails    = new WorkIndexing
         {
             Author = preface.QuerySelector("h3.heading a").InnerText,
             Title  = Sanitizer.TextSanitizer(preface.QuerySelector("h2.title").InnerText),
             WorkId = int.Parse(Sanitizer.ChapterToIdSanitizer(chapter
                                                               .QuerySelector("div.chapter h3.title a")
                                                               .Attributes["href"].Value)),
             Fandom = Sanitizer.ListToListSanitizer(details
                                                    .QuerySelectorAll("dd.fandom ul.commas li").Select(el => el.QuerySelector("a").InnerText)
                                                    .ToList()),
             Relationships = Sanitizer.ListToListSanitizer(details
                                                           .QuerySelectorAll("dd.relationship ul.commas li").Select(el => el.QuerySelector("a").InnerText)
                                                           .ToList()),
             Characters = Sanitizer.ListToListSanitizer(details
                                                        .QuerySelectorAll("dd.character ul.commas li")
                                                        .Select(el => el.QuerySelector("a").InnerText).ToList()),
             Category = Sanitizer.ListToListSanitizer(details.QuerySelectorAll("dd.category ul.commas li")
                                                      .Select(el => el.QuerySelector("a").InnerText).ToList()),
             Tags = Sanitizer.ListToListSanitizer(details
                                                  .QuerySelectorAll("dd.tags ul.commas li")
                                                  .Select(el => el.QuerySelector("a").InnerText).ToList()),
             Language = Sanitizer.LineSpaceSanitizer(details.QuerySelector("dd.language").InnerText),
             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))
         },