public static List <DraftPick> getDraft(HtmlAgilityPack.HtmlDocument doc) { List <DraftPick> mdpList = new List <DraftPick>(); // This is still messy from debugging the different values. It should be optimized. var dn = doc.DocumentNode; var dns = dn.SelectNodes("/html/body/div/div/div/table"); var attr = dns[1].Attributes; var attrs = attr.ToArray(); var style = attr.FirstOrDefault().Value; var ss = style.ToString(); bool hasStyle = ss.IndexOf("background-image: linear-gradient", StringComparison.OrdinalIgnoreCase) >= 0; foreach (var node in dns) { var nodeStyle = node.Attributes.FirstOrDefault().Value.ToString(); bool hasTheStyle = node.Attributes.FirstOrDefault().Value.ToString().IndexOf("background-image: linear-gradient", StringComparison.OrdinalIgnoreCase) >= 0; if (hasTheStyle) { var tr = node.SelectSingleNode("tr"); DraftPick DraftPick = createDraftEntry(tr); //Separate mock picks from actual picks DraftPick.actualPick = node.Attributes.FirstOrDefault().Value.ToString().IndexOf("darkslategray", StringComparison.OrdinalIgnoreCase) >= 0; mdpList.Add(DraftPick); } } var hasGradient = dns[1].Attributes.Contains("background-image"); return(mdpList); }
public static DraftPick createDraftEntry(HtmlNode tableRow) { var childNodes = tableRow.ChildNodes; var node1 = childNodes[1].InnerText; //pick number? string pickNumber = node1.Replace("\r", "") .Replace("\n", "") .Replace("\t", "") .Replace(" ", ""); var node3 = childNodes[3]; //team (and team image)? var teamCity = node3.ChildNodes[0].InnerText .Replace("\r", "") .Replace("\n", "") .Replace("\t", "") .TrimEnd(); var node5 = childNodes[5]; //Has Child Nodes - Player, School, Position, Reach/Value string playerName = node5.ChildNodes[1].InnerText .Replace("\r", "") .Replace("\n", "") .Replace("\t", "") .TrimEnd(); string playerSchoolBeforeChecking = node5.ChildNodes[3].InnerText .Replace("\r", "") .Replace("\n", "") .Replace("\t", "") .TrimEnd(); // this may have a space afterwards. string playerSchool = checkSchool(playerSchoolBeforeChecking); string playerPosition = node5.ChildNodes[5].InnerText .Replace("\r", "") .Replace("\n", "") .Replace("\t", "") .Replace(" ", ""); string reachValue = node5.ChildNodes[9].InnerText .Replace("\r", "") .Replace("\n", "") .Replace("\t", "") .Replace(" ", ""); DraftPick dp = new DraftPick(pickNumber, teamCity, playerName, playerSchool, playerPosition, reachValue); Console.WriteLine(dp.round); Console.WriteLine(dp.leagifyPoints); Console.WriteLine(dp.pickNumber); Console.WriteLine(dp.teamCity); Console.WriteLine(dp.playerName); Console.WriteLine(dp.school); Console.WriteLine(dp.position); Console.WriteLine(dp.reachValue); Console.WriteLine(dp.state); return(dp); }