public IActionResult Index() { AskCaro_QuestionnaireAspirateur.StackOverflowAspirateur main = new AskCaro_QuestionnaireAspirateur.StackOverflowAspirateur(); string countt = main.GetLastPageNumbers(); int count = int.Parse(countt); int simillar = 4736; for (int i = 317; i < count; i++) { var item = main.Start(i); foreach (var x in item) { List <QuestionModel> questionModels = new List <QuestionModel>(); QuestionModel questionModel = new QuestionModel(); questionModel.Title = x.title; questionModel.Similar = simillar; questionModel.LinkHref = x.hreflink; questionModel.TextDescription = main.GetDescrip(x.hreflink); questionModel.HtmlDescription = main.GetDescripHtml(x.hreflink); questionModel.Answers = new List <AnswerModel>(); foreach (var answers in main.GetBestanswers(x.hreflink)) { AnswerModel AnswerModel = new AnswerModel(); AnswerModel.Htmldescription = answers.Htmldescription; AnswerModel.Textdescription = answers.Textdescription; AnswerModel.voteCount = answers.voteCount; questionModel.Answers.Add(AnswerModel); } int maxZ = 0; if (questionModel.Answers.Count > 0) { maxZ = questionModel.Answers.Max(obj => obj.voteCount); questionModel.HtmlAnswers = questionModel.Answers.Where(obj => obj.voteCount == maxZ).FirstOrDefault().Htmldescription; } questionModels.Add(questionModel); //AskCaro_QuestionnaireAspirateur.GoogleAspirateur googleAspirateur = new AskCaro_QuestionnaireAspirateur.GoogleAspirateur(); //var listgoogle = googleAspirateur.Start(x.title, x.hreflink, "stackoverflow.com"); //foreach (var google in listgoogle) //{ // QuestionModel questionModelSimilar = new QuestionModel(); // questionModelSimilar.Title = google.Title; // questionModelSimilar.Similar = simillar; // questionModelSimilar.LinkHref = google.hreflink; // questionModelSimilar.TextDescription = main.GetDescrip(google.hreflink); // questionModelSimilar.HtmlDescription = main.GetDescrip(google.hreflink); // questionModelSimilar.HtmlAnswers = questionModel.HtmlAnswers; // questionModels.Add(questionModelSimilar); //} simillar++; //if (simillar % 40 == 0) //{ // System.Threading.Thread.Sleep(10000); //} _dbContext.Questions.AddRange(questionModels); var result = _dbContext.SaveChanges(); System.Threading.Thread.Sleep(1000); } } return(View()); }
public ActionResult run(string tag) { AskCaro_QuestionnaireAspirateur.StackOverflowAspirateur main = new AskCaro_QuestionnaireAspirateur.StackOverflowAspirateur(); string countt = main.GetLastPageNumbers(tag); int count = int.Parse(countt); int simillar = 0; for (int i = 0; i < count; i++) { var item = main.Start(i, tag); foreach (var x in item) { List <QuestionModel> questionModels = new List <QuestionModel>(); QuestionModel questionModel = new QuestionModel(); questionModel.Title = x.title; var checkDb = _dbContext.Questions.Where(y => y.Title == x.title).FirstOrDefault(); if (checkDb == null) { questionModel.Similar = simillar; questionModel.LinkHref = x.hreflink; questionModel.TextDescription = main.GetDescrip(x.hreflink); questionModel.HtmlDescription = main.GetDescripHtml(x.hreflink); var html = AskCaro_Web_MVC.Tools.WordsAnalyzer.RemoveTag(questionModel.HtmlDescription, "<code", "</code>"); html = AskCaro_Web_MVC.Tools.WordsAnalyzer.RemoveTag(html, "(", ")"); string InnerText = main.GetInnerText(html).Replace("\r", "").Replace("\n", ""); questionModel.Tag = AskCaro_Web_MVC.Tools.WordsAnalyzer.StringWords2Remove(x.title).Replace("-", " ") + " " + AskCaro_Web_MVC.Tools.WordsAnalyzer.StringWords2Remove(InnerText); questionModel.Answers = new List <AnswerModel>(); foreach (var answers in main.GetBestanswers(x.hreflink)) { AnswerModel AnswerModel = new AnswerModel(); AnswerModel.Htmldescription = answers.Htmldescription; AnswerModel.Textdescription = answers.Textdescription; AnswerModel.voteCount = answers.voteCount; questionModel.Answers.Add(AnswerModel); } int maxZ = 0; if (questionModel.Answers.Count > 0) { maxZ = questionModel.Answers.Max(obj => obj.voteCount); questionModel.HtmlAnswers = questionModel.Answers.Where(obj => obj.voteCount == maxZ).FirstOrDefault().Htmldescription; } _dbContext.Questions.Add(questionModel); var result = _dbContext.SaveChanges(); AskCaro_QuestionnaireAspirateur.GoogleAspirateur googleAspirateur = new AskCaro_QuestionnaireAspirateur.GoogleAspirateur(); var listgoogle = googleAspirateur.Start(x.title, x.hreflink, "stackoverflow.com"); foreach (var google in listgoogle) { if (google.Title != questionModel.Title) { QuestionModel questionModelSimilar = new QuestionModel(); questionModelSimilar.Title = google.Title; questionModelSimilar.Similar = simillar; questionModelSimilar.LinkHref = google.hreflink; questionModelSimilar.TextDescription = main.GetDescrip(google.hreflink); questionModelSimilar.HtmlDescription = main.GetDescrip(google.hreflink); var htmlgoogle = AskCaro_Web_MVC.Tools.WordsAnalyzer.RemoveTag(questionModelSimilar.HtmlDescription, "<code", "</code>"); htmlgoogle = AskCaro_Web_MVC.Tools.WordsAnalyzer.RemoveTag(htmlgoogle, "(", ")"); string InnerTextgoogle = main.GetInnerText(htmlgoogle).Replace("\r", "").Replace("\n", ""); questionModel.Tag = AskCaro_Web_MVC.Tools.WordsAnalyzer.StringWords2Remove(google.Title).Replace("-", " ") + " " + AskCaro_Web_MVC.Tools.WordsAnalyzer.StringWords2Remove(InnerTextgoogle); questionModelSimilar.HtmlAnswers = questionModel.HtmlAnswers; questionModels.Add(questionModelSimilar); } } simillar++; if (simillar % 40 == 0) { System.Threading.Thread.Sleep(10000); } System.Threading.Thread.Sleep(1000); } } } return(View()); }