Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. using AngleSharp;
  2. using AngleSharp.Dom;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace ConsoleApp1
  10. {
  11. class Program
  12. {
  13. public static void Main(string[] args)
  14. {
  15. var rame = ParseHtml();
  16.  
  17.  
  18. foreach(var item in rame)
  19. {
  20. Console.WriteLine($"{item.Id} {item.Title} {item.DirectedBy} {item.OriginalDate}");
  21. }
  22.  
  23.  
  24. Console.ReadLine();
  25. }
  26.  
  27. public static IEnumerable<Model> ParseHtml()
  28. {
  29. var config = Configuration.Default.WithDefaultLoader();
  30. var address = "https://en.wikipedia.org/wiki/List_of_The_Big_Bang_Theory_episodes";
  31. var document = BrowsingContext.New(config).OpenAsync(address).Result;
  32. var cellSelector = ".vevent";
  33. var cells = document.QuerySelectorAll(cellSelector).ToList();
  34.  
  35. foreach (var ParentItem in cells)
  36. {
  37. var ChildNodes = ParentItem.ChildNodes;
  38. var Model = new Model();
  39. Model.Init(ChildNodes);
  40. yield return Model;
  41. }
  42.  
  43. }
  44. }
  45.  
  46. public class Model
  47. {
  48. public string Id { get; set; }
  49. public string Title { get; set; }
  50. public string DirectedBy { get; set; }
  51. public string WrittenBy { get; set; }
  52. public string OriginalDate { get; set; }
  53.  
  54. public void Init(INodeList Model)
  55. {
  56. this.Id = Model[1].TextContent;
  57. this.Title = Model[2].TextContent;
  58. this.DirectedBy = Model[3].TextContent;
  59. this.WrittenBy = Model[4].TextContent;
  60. this.OriginalDate = Model[5].TextContent;
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement