Created
November 13, 2013 14:29
-
-
Save compil3/7450004 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Data.SqlServerCe; | |
using System.IO; | |
using System.Linq; | |
using System.Xml.Linq; | |
using HtmlAgilityPack; | |
namespace NHLScraper | |
{ | |
//creates an xml file with all the NHL teams full name and abbreviation | |
public class GetAbbreviation | |
{ | |
private string Source; | |
public void TeamsParser(string Source) | |
{ | |
this.Source = Source; | |
ParseTeams(); | |
} | |
private void ParseTeams() | |
{ | |
HtmlNode.ElementsFlags.Remove("option"); | |
var htmlDoc = new HtmlDocument { OptionFixNestedTags = true }; | |
htmlDoc.LoadHtml(Source); | |
var teamListing = htmlDoc.DocumentNode | |
.SelectNodes("//select[@id='team']//option[position() > 1]") | |
.Select(node => new { team = node.InnerText.Trim(), abbrev = node.Attributes["value"].Value }) | |
.ToList(); | |
var xmlDoc = new XElement("NHL-TEAMS", | |
new XAttribute("Created", DateTime.Now.ToString())); | |
foreach (var clean in teamListing) | |
{ | |
var addValue = new XElement("TEAM", | |
new XElement("Fullname", clean.team), | |
new XElement("Short", clean.abbrev)); | |
xmlDoc.Add(addValue); | |
Console.WriteLine(clean.team + " " + clean.abbrev); | |
} | |
xmlDoc.Save(AppDomain.CurrentDomain.BaseDirectory + "/Doc/teams.xml"); | |
//testing writing to db | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment