PageRenderTime 130ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Kronos/Kronos/CLASSES/WebScraper.cs

https://github.com/lle/soen341kronos
C# | 59 lines | 48 code | 10 blank | 1 comment | 0 complexity | 24d69d340e2673e4e1f2bf8a5d7a879d MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Threading;
  6. using HtmlAgilityPack;
  7. namespace Kronos.CLASSES
  8. {
  9. public class WebScraper
  10. {
  11. #region Variables
  12. private HtmlWeb web;
  13. private HtmlDocument doc;
  14. private HtmlNodeCollection tables;
  15. private HtmlNodeCollection rows;
  16. private HtmlNodeCollection cols;
  17. private string course_code;
  18. private string semester_code;
  19. private string coursenumber_code;
  20. #endregion
  21. #region Constructor
  22. public WebScraper(string coursetag, string coursenumber, string semesternumber)
  23. {
  24. course_code = coursetag;
  25. coursenumber_code = coursenumber;
  26. semester_code = semesternumber;
  27. }
  28. #endregion
  29. #region ParseData
  30. public void process_course()
  31. {
  32. string url = "http://fcms.concordia.ca/fcms/asc002_stud_all.aspx?yrsess=2012"
  33. + semester_code + "&course=" + course_code + "&courno=" + coursenumber_code + "%20&campus=&type=U";
  34. web = new HtmlWeb();
  35. doc = web.Load(url);
  36. try
  37. {
  38. //check this logic out, get the table ID and then process data from the rows and columns of the table.
  39. var GetTableID = doc.GetElementbyId("ctl00_PageBody_tblBodyShow1").Descendants("tr").Select(x => x.Elements("td").Select(y => y.InnerText).ToArray());
  40. System.Diagnostics.Debug.WriteLine(GetTableID);
  41. }
  42. catch (Exception error)
  43. {
  44. throw new Exception(error.ToString());
  45. }
  46. }
  47. #endregion
  48. }
  49. }