Created
November 1, 2013 19:36
-
-
Save compil3/7270765 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
| public void ParseHtml() | |
| { | |
| var htmlDoc = new HtmlDocument(); | |
| htmlDoc.LoadHtml(Source); | |
| var cells = htmlDoc.DocumentNode | |
| .SelectNodes("/html/body/div[2]/div[4]/div/div[3]/table/tbody/tr[THIS tr changes to tr[1] etc for each xpath needed]/td") // use the right XPath rather than looping manually | |
| .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()), | |
| //generate the elements based on the parsed cells | |
| cells.Skip(1) | |
| .Zip(elementNames, (Value, Name) => new XElement(Name, Value)) | |
| .Where(element => !String.IsNullOrEmpty(element.Value)) | |
| ) | |
| ); | |
| xmlDoc.Save("sparsed.xml"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment