// Analyse Html Text private bool AnalyseAndCreateQuizs(string html) { // Create var HtmlDoc = new HtmlAgilityPack.HtmlDocument(); HtmlDoc.LoadHtml(html); // Analyse var xpath = @"//table[@id=""output_list_box""]/tr[@id]"; var Articles = HtmlDoc.DocumentNode.SelectNodes(xpath); if(Articles == null) { // Error return false; } foreach(var Artc in Articles) { // Generate Quiz Quiz q = new Quiz(); // QuizID q.QuizID = Convert.ToInt32( Artc.SelectSingleNode("descendant::td[3]/p/a").Attributes["href"].Value .Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last() ); // Genre q.Genre = Artc.SelectSingleNode("descendant::td[1]/p").InnerText.Replace(" ",""); // Diff q.Diff = DiffStringToInt(Artc.SelectSingleNode("descendant::td[2]/p").InnerText); // Question q.Question = Artc.SelectSingleNode("descendant::td[3]/p/a").InnerText.Trim(); // selections var Selections = (from s in Artc.SelectSingleNode("descendant::td[3]/p/a").Attributes["title"].Value .Substring(4).Split(new char[] { '【', '】'}, StringSplitOptions.RemoveEmptyEntries) where s.Replace(" ", "").Length > 0 select s).ToArray(); q.Selection1 = Selections[0]; q.Selection2 = Selections[1]; q.Selection3 = Selections[2]; q.Selection4 = Selections[3]; // IsEnableSelections q.IsEnabledSelections = Selections[3].IndexOf("不明") <= -1; // Insert Quizs.Add(q); } return true; }
// 条件に一致するかどうかを返却 private bool _IsMatchQuiz(Quiz q) { var Ad = q.AData; return (ShowRate == null || Ad.Rate <= ShowRate.Value) && (MaxShow == null || Ad.QstNumber <= MaxShow) && (MinShow == null || Ad.QstNumber >= MinShow) && (AnsRate == null || (Ad.QstNumber > 0 && (double)Ad.AnsNumber/Ad.QstNumber*100 <= AnsRate.Value)) && ((q.Diff == 1 && Diff1) || (q.Diff == 2 && Diff2) || (q.Diff == 3 && Diff3)) && ( (GenreB && q.Genre.IndexOf("文系") >= 0) || (GenreR && q.Genre.IndexOf("理系") >= 0) || (GenreG && q.Genre.IndexOf("芸能") >= 0) || (GenreZ && q.Genre.IndexOf("雑学") >= 0) || (GenreS && q.Genre.IndexOf("スポーツ") >= 0) || (GenreA && q.Genre.IndexOf("アニメゲーム") >= 0) ); }