tankcr

Untitled

Jun 14th, 2014
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Net;
  7. using System.IO;
  8. using HtmlAgilityPack;
  9.  
  10. namespace ROD_Deck_Builder
  11. {
  12.     public class Pagedata
  13.     {
  14.         HtmlAgilityPack.HtmlDocument pageData;
  15.  
  16.         public HtmlAgilityPack.HtmlDocument PageData
  17.         {
  18.             get { return pageData; }
  19.             set { pageData = value; }
  20.         }
  21.  
  22.         public Pagedata()
  23.         {
  24.  
  25.         }
  26.     }
  27.     public class GetPage
  28.     {
  29.         public static Pagedata GetPageData(string url)
  30.         {
  31.             WebRequest request = WebRequest.Create(url);
  32.             WebResponse response = request.GetResponse();
  33.             Stream data = response.GetResponseStream();
  34.             HtmlDocument mydoc = new HtmlDocument();
  35.             mydoc.OptionFixNestedTags = true;
  36.             mydoc.Load(data);
  37.             if (mydoc.ParseErrors != null && mydoc.ParseErrors.Count() > 0)
  38.             {
  39.                 // Handle any parse errors as required
  40.  
  41.             }
  42.             else
  43.             {
  44.  
  45.                 if (mydoc.DocumentNode != null)
  46.                 {
  47.                     HtmlAgilityPack.HtmlNode bodyNode = mydoc.DocumentNode.SelectSingleNode("//body");
  48.  
  49.                     if (bodyNode != null)
  50.                     {
  51.                         // Do something with bodyNode
  52.                         mydoc.DocumentNode.SelectSingleNode("//table[@class='witiable sortable']");
  53.                     }
  54.                     return mydoc;
  55.                 }
  56.             }
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment