private void GetSeasonTeProjections(ref Projections projections) { WebScraper scraper = new WebScraper(null, null, null); HtmlDocument document = scraper.Scrape("https://www.fantasypros.com/nfl/projections/te.php?week=draft"); //HtmlDocument document = scraper.Scrape("https://web.archive.org/web/20150908002135/http://www.fantasypros.com/nfl/projections/te.php?week=draft"); //get projection-data table from html HtmlNode table = document.GetElementbyId(FantasyProsProjectionTable).Descendants().Where(t => t.Name == "tbody").FirstOrDefault <HtmlNode>(); //loop through rows in projection table foreach (HtmlNode row in table.SelectNodes("./tr")) { //create new datarow Player player = new Player(); //parse name and team out of player cell FantasyProsParser parser = new FantasyProsParser(row.SelectSingleNode("./td[1]")); //convert to nfl values NflConverter converter = new NflConverter(parser.Name, parser.Team); //set row values player.Id = projections.SeasonProjectionPlayers.Count + 1; player.Name = converter.Name; player.Position = "TE"; player.NflTeam = converter.NflTeam; player.Receptions = decimal.Parse(row.SelectSingleNode("./td[2]").InnerText) / 16; player.ReceivingYards = decimal.Parse(row.SelectSingleNode("./td[3]").InnerText) / 16; player.ReceivingTouchdowns = decimal.Parse(row.SelectSingleNode("./td[4]").InnerText) / 16; //add datarow to datatable projections.SeasonProjectionPlayers.Add(player); } }
private void GetNextWeekWrProjections(ref Projections projections) { WebScraper scraper = new WebScraper(null, null, null); HtmlDocument document = scraper.Scrape("https://www.fantasypros.com/nfl/projections/wr.php?week=" + CurrentWeek); //HtmlDocument document = scraper.Scrape("https://web.archive.org/web/20150918083129/http://www.fantasypros.com/nfl/projections/wr.php"); //get projection-data table from html HtmlNode table = document.GetElementbyId(FantasyProsProjectionTable).Descendants().Where(t => t.Name == "tbody").FirstOrDefault <HtmlNode>(); //loop through rows in projection table //loop through rows in projection table List <HtmlNode> rows = table.SelectNodes("./tr").ToList <HtmlNode>(); if (rows.Count > 1) { foreach (HtmlNode row in rows) { //create new datarow Player player = new Player(); //parse name and team out of player cell FantasyProsParser parser = new FantasyProsParser(row.SelectSingleNode("./td[1]")); //set row values player.Id = projections.WeekProjectionPlayers.Count + 1; player.Name = parser.Name; player.Position = "WR"; player.NflTeam = parser.Team; player.RushingYards = decimal.Parse(row.SelectSingleNode("./td[3]").InnerText); player.RushingTouchdowns = decimal.Parse(row.SelectSingleNode("./td[4]").InnerText); player.Receptions = decimal.Parse(row.SelectSingleNode("./td[5]").InnerText); player.ReceivingYards = decimal.Parse(row.SelectSingleNode("./td[6]").InnerText); player.ReceivingTouchdowns = decimal.Parse(row.SelectSingleNode("./td[7]").InnerText); //add datarow to datatable projections.WeekProjectionPlayers.Add(player); } } }
private void GetNextWeekQbData(ref DfsData dfsData, string url) { WebScraper scraper = new WebScraper(null, null, null); HtmlDocument document = scraper.Scrape(url + QbSuffix); //get projection-data table from html HtmlNode table = document.GetElementbyId(FantasyProsDataTable).Descendants().Where(t => t.Name == "tbody").FirstOrDefault <HtmlNode>(); //loop through rows in projection table List <HtmlNode> rows = table.SelectNodes("./tr").ToList <HtmlNode>(); if (rows.Count > 1) { foreach (HtmlNode row in rows) { //if player has cost per point for this week if (row.SelectSingleNode("./td[13]").InnerText.Length > 0) { //create new datarow Player player = new Player(); //parse name and team out of player cell FantasyProsParser parser = new FantasyProsParser(row.SelectSingleNode("./td[1]")); //set row values player.Id = dfsData.Quarterbacks.Count + 1; player.Name = parser.Name; player.Position = "QB"; player.NflTeam = parser.Team; player.FantasyPoints = decimal.Parse(row.SelectSingleNode("./td[11]").InnerText.Replace("pts", "")); player.Salary = int.Parse(row.SelectSingleNode("./td[12]").InnerText.Replace("$", "").Replace(",", "")); player.CostPerPoint = int.Parse(row.SelectSingleNode("./td[13]").InnerText.Replace("$", "")); //add datarow to datatable dfsData.Quarterbacks.Add(player); } } } }
public List <Player> Scrape(string position, int week) { if (position == null || position == "") { throw new Exception("Position cannot be empty."); } if (week < 0 || week > 17) { throw new Exception("Invalid week."); } WebScraper scraper = new WebScraper(null, null, null); HtmlDocument document = scraper.Scrape(GetUrl(position, week)); List <Player> players = new List <Player>(); //get projection-data table from html HtmlNode table = document.GetElementbyId(_dataTableName).Descendants().Where(t => t.Name == "tbody").FirstOrDefault <HtmlNode>(); //loop through rows in projection table foreach (HtmlNode row in table.SelectNodes("./tr")) { //create new datarow Player player = new Player(); //parse name and team out of player cell FantasyProsParser parser = new FantasyProsParser(row.SelectSingleNode("./td[1]")); //set row values player.Name = parser.Player; player.Position = position; player.Team = parser.Team; player.GamesPlayed = 1; switch (position) { case "QB": player.PassingYards = decimal.Parse(row.SelectSingleNode("./td[4]").InnerText) / 16; player.PassingTouchdowns = decimal.Parse(row.SelectSingleNode("./td[5]").InnerText) / 16; player.Interceptions = decimal.Parse(row.SelectSingleNode("./td[6]").InnerText) / 16; player.RushingYards = decimal.Parse(row.SelectSingleNode("./td[8]").InnerText) / 16; player.RushingTouchdowns = decimal.Parse(row.SelectSingleNode("./td[9]").InnerText) / 16; break; case "RB": player.RushingYards = decimal.Parse(row.SelectSingleNode("./td[3]").InnerText) / 16; player.RushingTouchdowns = decimal.Parse(row.SelectSingleNode("./td[4]").InnerText) / 16; player.Receptions = decimal.Parse(row.SelectSingleNode("./td[5]").InnerText) / 16; player.ReceivingYards = decimal.Parse(row.SelectSingleNode("./td[6]").InnerText) / 16; player.ReceivingTouchdowns = decimal.Parse(row.SelectSingleNode("./td[7]").InnerText) / 16; break; case "WR": player.Receptions = decimal.Parse(row.SelectSingleNode("./td[5]").InnerText) / 16; player.ReceivingYards = decimal.Parse(row.SelectSingleNode("./td[6]").InnerText) / 16; player.ReceivingTouchdowns = decimal.Parse(row.SelectSingleNode("./td[7]").InnerText) / 16; break; case "TE": player.Receptions = decimal.Parse(row.SelectSingleNode("./td[2]").InnerText) / 16; player.ReceivingYards = decimal.Parse(row.SelectSingleNode("./td[3]").InnerText) / 16; player.ReceivingTouchdowns = decimal.Parse(row.SelectSingleNode("./td[4]").InnerText) / 16; break; case "K": player.FantasyPoints = decimal.Parse(row.SelectSingleNode("./td[5]").InnerText) / 16; break; case "DST": player.FantasyPoints = decimal.Parse(row.SelectSingleNode("./td[10]").InnerText) / 16; if (player.Name == "Arizona Cardinals") { player.Team = "ARI"; } else if (player.Name == "Atlanta Falcons") { player.Team = "ATL"; } else if (player.Name == "Baltimore Ravens") { player.Team = "BAL"; } else if (player.Name == "Buffalo Bills") { player.Team = "BUF"; } else if (player.Name == "Carolina Panthers") { player.Team = "CAR"; } else if (player.Name == "Chicago Bears") { player.Team = "CHI"; } else if (player.Name == "Cincinnati Bengals") { player.Team = "CIN"; } else if (player.Name == "Cleveland Browns") { player.Team = "CLE"; } else if (player.Name == "Dallas Cowboys") { player.Team = "DAL"; } else if (player.Name == "Denver Broncos") { player.Team = "DEN"; } else if (player.Name == "Detroit Lions") { player.Team = "DET"; } else if (player.Name == "Green Bay Packers") { player.Team = "GB"; } else if (player.Name == "Houston Texans") { player.Team = "HOU"; } else if (player.Name == "Indianapolis Colts") { player.Team = "IND"; } else if (player.Name == "Jacksonville Jaguars") { player.Team = "JAC"; } else if (player.Name == "Kansas City Chiefs") { player.Team = "KC"; } else if (player.Name == "Los Angeles Chargers") { player.Team = "LAC"; } else if (player.Name == "Los Angeles Rams") { player.Team = "LAR"; } else if (player.Name == "Miami Dolphins") { player.Team = "MIA"; } else if (player.Name == "Minnesota Vikings") { player.Team = "MIN"; } else if (player.Name == "New England Patriots") { player.Team = "NE"; } else if (player.Name == "New Orleans Saints") { player.Team = "NO"; } else if (player.Name == "New York Giants") { player.Team = "NYG"; } else if (player.Name == "New York Jets") { player.Team = "NYJ"; } else if (player.Name == "Oakland Raiders") { player.Team = "OAK"; } else if (player.Name == "Philadelphia Eagles") { player.Team = "PHI"; } else if (player.Name == "Pittsburgh Steelers") { player.Team = "PIT"; } else if (player.Name == "Seattle Seahawks") { player.Team = "SEA"; } else if (player.Name == "San Francisco 49ers") { player.Team = "SF"; } else if (player.Name == "Tampa Bay Buccaneers") { player.Team = "TB"; } else if (player.Name == "Tennessee Titans") { player.Team = "TEN"; } else if (player.Name == "Washington Redskins") { player.Team = "WAS"; } break; default: break; } //add datarow to datatable players.Add(player); } return(players); }