static public HitomiArticle ParseGallery(string source) { HitomiArticle article = new HitomiArticle(); HtmlDocument document = new HtmlDocument(); document.LoadHtml(source); HtmlNode nodes = document.DocumentNode.SelectSingleNode("//div[@class='content']"); article.Magic = nodes.SelectSingleNode("./div[3]/h1/a").GetAttributeValue("href", "").Split('/')[2].Split('.')[0]; foreach (var tr in document.DocumentNode.SelectNodes("//div[@class='gallery-info']/table/tr").ToList()) { var tt = tr.SelectSingleNode("./td").InnerText.ToLower().Trim(); if (tt == "group") { article.group = tr.SelectNodes(".//a")?.Select(x => x.InnerText.Trim()).ToArray(); } else if (tt == "characters") { article.character = tr.SelectNodes(".//a")?.Select(x => x.InnerText.Trim()).ToArray(); } } return(article); }
static public HitomiArticle ParseGalleryBlock(string source) { HitomiArticle article = new HitomiArticle(); HtmlDocument document = new HtmlDocument(); document.LoadHtml(source); HtmlNode nodes = document.DocumentNode.SelectNodes("/div")[0]; article.Magic = nodes.SelectSingleNode("./a").GetAttributeValue("href", ""); try { article.Thumbnail = nodes.SelectSingleNode("./a//img").GetAttributeValue("data-src", "").Substring("//tn.hitomi.la/".Length).Replace("smallbig", "big"); } catch { article.Thumbnail = nodes.SelectSingleNode("./a//img").GetAttributeValue("src", "").Substring("//tn.hitomi.la/".Length); } article.Title = nodes.SelectSingleNode("./h1").InnerText; try { article.artist = nodes.SelectNodes(".//div[@class='artist-list']//li").Select(node => node.SelectSingleNode("./a").InnerText).ToArray(); } catch { article.artist = new[] { "NA" }; } var contents = nodes.SelectSingleNode("./div[2]/table"); try { article.parody = contents.SelectNodes("./tr[1]/td[2]/ul/li").Select(node => node.SelectSingleNode(".//a").InnerText).ToArray(); } catch { } article.Type = contents.SelectSingleNode("./tr[2]/td[2]/a").InnerText; try { article.Language = LegalizeLanguage(contents.SelectSingleNode("./tr[3]/td[2]/a").InnerText); } catch { } try { article.Tags = contents.SelectNodes("./tr[4]/td[2]/ul/li").Select(node => LegalizeTag(node.SelectSingleNode(".//a").InnerText)).ToArray(); } catch { } article.Posted = nodes.SelectSingleNode("./div[2]/p").InnerText; return(article); }
private static HitomiArticle parse_info(string html) { HitomiArticle article = new HitomiArticle(); HtmlDocument document = new HtmlDocument(); document.LoadHtml(html); HtmlNode node = document.DocumentNode.SelectNodes("//main/div")[0]; article.Thumbnail = "https://hiyobi.me" + node.SelectSingleNode(".//img").GetAttributeValue("src", ""); var span = node.SelectSingleNode("./span"); article.Title = span.SelectSingleNode("./h5/a/b").InnerText; var table = span.SelectNodes("./table/tr"); var table_dic = new Dictionary <string, HtmlNode>(); table.ToList().ForEach(x => table_dic.Add(x.SelectSingleNode("./td[1]").InnerText.Remove(2), x)); if (table_dic.ContainsKey("작가")) { try { var group = new List <string>(); article.artist = table_dic["작가"].SelectNodes("./td[2]/a").ToList().Select(x => { if (x.InnerText.Contains("(")) { group.Add(x.InnerText.Split('(')[1].Split(')')[0].Trim()); } return(x.InnerText.Split('(')[0].Trim()); }).ToArray(); if (group.Count != 0) { article.group = group.ToArray(); } } catch { } } if (table_dic.ContainsKey("원작")) { try { article.parody = table_dic["원작"].SelectNodes("./td[2]/a").ToList().Select(x => $"{x.GetAttributeValue("data-original", "")}|{x.InnerText}").ToArray(); } catch { } } if (table_dic.ContainsKey("종류")) { try { article.Type = table_dic["종류"].SelectSingleNode("./td[2]/a").InnerText; } catch { } } if (table_dic.ContainsKey("태그")) { try { article.Tags = table_dic["태그"].SelectNodes("./td[2]/a").ToList().Select(x => $"{x.GetAttributeValue("data-original", "")}|{x.InnerText}").ToArray(); } catch { } } if (table_dic.ContainsKey("캐릭")) { try { article.character = table_dic["캐릭"].SelectNodes("./td[2]/a").ToList().Select(x => $"{x.GetAttributeValue("data-original", "")}|{x.InnerText}").ToArray(); } catch { } } return(article); }