tankcr

Untitled

Jun 16th, 2014
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.35 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 GetPage
  13.     {
  14.         public static HtmlAgilityPack.HtmlNode GetPageData(string url)
  15.         {
  16.  
  17.             string weburl = url;
  18.             WebClient dl = new WebClient();
  19.             dl.Encoding = Encoding.UTF8;
  20.             string page = dl.DownloadString(weburl);
  21.             HtmlDocument mydoc = new HtmlDocument();
  22.             mydoc.LoadHtml(page);
  23.  
  24.             HtmlNode table = mydoc.DocumentNode.SelectSingleNode("//table[@class='witiable sortable']");
  25.             var tableHeaders = table.SelectNodes("tr[th]/th");
  26.             foreach (var header in tableHeaders)
  27.             {
  28.                 string columnName = header.InnerText.Trim();
  29.             }
  30.  
  31.             var tableRows = table.SelectNodes("tr").OfType<HtmlNode>().Skip(1);
  32.             foreach (var row in tableRows)
  33.             {
  34.                 var rowColumns = row.SelectNodes("td");
  35.                 foreach (var column in rowColumns)
  36.                 {
  37.                     string columnValue = column.InnerText.Trim();
  38.                     Card cardtable = new Card();
  39.  
  40.                 }
  41.             }
  42.            return table;
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment