Skip to content

Instantly share code, notes, and snippets.

@compil3
Created November 4, 2013 07:42
Show Gist options
  • Select an option

  • Save compil3/7299318 to your computer and use it in GitHub Desktop.

Select an option

Save compil3/7299318 to your computer and use it in GitHub Desktop.
public void ParseHtml()
{
var htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(Source);
var cells = htmlDoc.DocumentNode
.SelectNodes("//table[@class='data stats']/tbody/tr/td").OfType<XmlNode>()// can't get it to loop
.Select(node => node.InnerText.Trim())
.ToList();
var elementNames = new[] { "Name", "Team", "Pos", "GP", "G", "A", "Pts", "PlusMinus", "PIM", "PP", "SH", "GW", "OT", "Shots", "ShotPctg", "TOIPerGame", "ShiftsPerGame", "FOWinPctg" };
var xmlDoc = new XElement("Stats", new XAttribute("Date", DateTime.Now.ToShortDateString()),
new XElement("Player", new XAttribute("Rank", cells.First()),
cells.Skip(1)
.Zip(elementNames, (Value, Name) => new XElement(Name, Value))
.Where(element => !String.IsNullOrEmpty(element.Value))
)
);
xmlDoc.Save("parsed.xml");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment