private static List <string> GetTPLinks() { HtmlDocument boardHtml = new HtmlDocument(); boardHtml.LoadHtml(Driver.GetInstance.WebDrive.PageSource); List <string> TPLinks = new List <string>(); foreach (var Nodo in boardHtml.DocumentNode.CssSelect(".ig-title.title.item_link")) { HtmlAttributeCollection atts = Nodo.Attributes; string title = atts.Where(a => a.Name.ToLower() == "title").FirstOrDefault().Value; if (title.Contains("Trabajo")) { TPLinks.Add(atts.Where(a => a.Name.ToLower() == "href").FirstOrDefault().Value); } } return(TPLinks); }
private void TagContentSearch_Click(object sender, RoutedEventArgs e) { string TagName = GUITagBox.Text; string[] Attributes = GUITagAttributeBox.Text.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);; List <HtmlNode> acceptedNodes = new List <HtmlNode>(); // those among matchingNodes that have all required attributes FolderArea.Text = ""; foreach (string filePath in LocalFolderFiles) { string fileContents = File.ReadAllText(filePath); HtmlAgilityPack.HtmlDocument theHTML = new HtmlDocument(); theHTML.LoadHtml(fileContents); IEnumerable <HtmlNode> matchingNodes = theHTML.DocumentNode.Descendants(TagName); foreach (var matchingNode in matchingNodes) { HtmlAttributeCollection matchingAttrs = matchingNode.Attributes; bool AcceptThisNode = true; foreach (string attribute in Attributes) { HtmlAttribute attr = matchingAttrs[0]; int Number = matchingAttrs.Where(x => x.Name == attribute).Count(); if (Number == 0) { //this matchingNode did not make it - go to next outer loop AcceptThisNode = false; break; } } if (AcceptThisNode) { if (matchingNode.InnerHtml != "" && matchingNode.InnerHtml != null) { acceptedNodes.Add(matchingNode); } } } } if (acceptedNodes.Count() == 0) { FolderArea.Text = "No matching tags were found."; } else { foreach (HtmlNode node in acceptedNodes) { FolderArea.Text += node.InnerHtml; } } }//end fn
private static List <string> GetCourses() { HtmlDocument boardHtml = new HtmlDocument(); boardHtml.LoadHtml(Driver.GetInstance.WebDrive.PageSource); List <string> Courses = new List <string>(); foreach (var Nodo in boardHtml.DocumentNode.CssSelect(".ic-DashboardCard__link")) { HtmlAttributeCollection atts = Nodo.Attributes; Courses.Add(atts.Where(a => a.Name.ToLower() == "href").FirstOrDefault().Value); } return(Courses); }
protected IEnumerable <ViewLayerControlAttribute> ConvertAttributes(HtmlAttributeCollection attributeCollection) { var convertedAttributes = attributeCollection .Where(attr => AttributeMap.ContainsKey(attr.Name)) .Select(attr => { if (attr.QuoteType == AttributeValueQuote.DoubleQuote) { return(new ViewLayerControlAttribute($"{AttributeMap[attr.Name]}", $"\"{attr.Value}\"")); } return(new ViewLayerControlAttribute($"{AttributeMap[attr.Name]}", $"'{attr.Value}'")); }); return(convertedAttributes); }
private static List <string> GetTPLinksInGrades() { HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(Driver.GetInstance.WebDrive.PageSource); List <string> TPLinks = new List <string>(); var selectNodes = doc.DocumentNode.Descendants("a"); foreach (var Nodo in selectNodes) { if (Nodo.InnerText.Contains("Trabajo")) { HtmlAttributeCollection atts = Nodo.Attributes; String tp = atts.Where(a => a.Name.ToLower() == "href").FirstOrDefault().Value; TPLinks.Add(tp.Substring(0, tp.IndexOf("submissions") - 1)); } } return(TPLinks); }
private static void LoadQuestions(TP tp) { //scrap TP page HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(Driver.GetInstance.WebDrive.PageSource); //go for each matching type answer HtmlNodeCollection selectNodes = doc.DocumentNode.SelectNodes("//select[@id]"); if (selectNodes != null) { foreach (var Node in selectNodes) { //load answer <select> attributes HtmlAttributeCollection atts = Node.Attributes; //gets answer id string answerId = atts.Where(a => a.Name.ToLower() == "id").FirstOrDefault().Value; //gets question id and keeps only the number Regex regex = new Regex(@"(?<=question_)(.+?)(?=_)"); string idQuestion = regex.Match(answerId).Value; //checks if it was previously loaded if (tp.Questions.Any(q => q.Id == idQuestion)) { if (!tp.CurrentQuestions.Any(q => q.Id == idQuestion)) { tp.CurrentQuestions.Add(tp.Questions.Where(q => q.Id == idQuestion).FirstOrDefault()); } } else { if (tp.CurrentQuestions.Any(q => q.Id == idQuestion)) { foreach (var SubNode in Node.Descendants("option")) { string option = SubNode.Attributes .Where(a => a.Name.ToLower() == "value") .FirstOrDefault().Value; if (!string.IsNullOrEmpty(option)) { tp.CurrentQuestions .Where(q => q.Id == idQuestion) .FirstOrDefault() .Answers.Add(Tuple.Create(answerId, option)); } } } else { Question newQ = new Question() { Id = idQuestion, Type = "matching_question" }; foreach (var SubNode in Node.Descendants("option")) { string option = SubNode.Attributes .Where(a => a.Name.ToLower() == "value") .FirstOrDefault().Value; if (!string.IsNullOrEmpty(option)) { newQ.Answers.Add(Tuple.Create(answerId, option)); } } tp.CurrentQuestions.Add(newQ); } } } } //go for each input type answer HtmlNodeCollection inputNodes = doc.DocumentNode.SelectNodes("//input[@id]"); if (inputNodes != null) { foreach (var Node in doc.DocumentNode.SelectNodes("//input[@id]")) { //load answer <input> attributes HtmlAttributeCollection atts = Node.Attributes; //gets answer id string answerId = atts.Where(a => a.Name.ToLower() == "id").FirstOrDefault().Value; //gets question id and keeps only the number Regex regex = new Regex(@"(?<=question_)(.+?)(?=_)"); string idQuestion = regex.Match(answerId).Value; //checks if it was previously loaded if (tp.Questions.Any(q => q.Id == idQuestion)) { if (!tp.CurrentQuestions.Any(q => q.Id == idQuestion)) { tp.CurrentQuestions.Add(tp.Questions.Where(q => q.Id == idQuestion).FirstOrDefault()); } } else { if (tp.CurrentQuestions.Any(q => q.Id == idQuestion)) { tp.CurrentQuestions .Where(q => q.Id == idQuestion) .FirstOrDefault() .Answers.Add(Tuple.Create(answerId, string.Empty)); } else { //gets answer type, creates new question string type; string answerType = atts.Where(a => a.Name.ToLower() == "type").FirstOrDefault().Value; if (answerType == "checkbox") { type = "multiple_answers_question"; } else { type = "multiple_choice_question"; } tp.CurrentQuestions.Add(new Question() { Id = idQuestion, Type = type, Answers = { Tuple.Create(answerId, string.Empty) } }); } } } } foreach (Question q in tp.CurrentQuestions) { if (!q.FullyLoaded) { tp.Questions.Add(q); } q.FullyLoaded = true; } }