Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Mime;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using HtmlAgilityPack;
using System.Xml;
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/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()),
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/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()),
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()),
public void ParseHtml()
{
var htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(Source);
var cells = htmlDoc.DocumentNode
.SelectNodes("//table[@class='data stats']/tbody/tr/td") // can't get it to loop
.Select(node => node.InnerText.Trim())
.ToList();
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();
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();
public void ParseTeams()
{
var htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(Source);
var teamName = htmlDoc.DocumentNode
.SelectNodes("//select[@id='team']//option[position() > 1]")
.Select(node => node.InnerText.Trim())
.ToList();
public void ParseTeams()
{
var htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(Source);
var teamName = htmlDoc.DocumentNode
.SelectNodes("//select[@id='team']//option[position() > 1]")
.Select(node => node.InnerText.Trim())
.ToList();
public void ParseTeams()
{
HtmlAgilityPack.HtmlNode.ElementsFlags.Remove("option");
var htmlDoc = new HtmlDocument();
htmlDoc.OptionFixNestedTags = true;
htmlDoc.LoadHtml(Source);
var teamName = htmlDoc.DocumentNode
.SelectNodes("//select[@id='team']//option[position() > 1]")