private void button2_Click(object sender, EventArgs e) { if (curMatch > 0) { MatchState result = new MatchState(); result = ParserSites.GetMatch(page2); string[] colName = { "date", "orbitr", "trainerhome", "traineraway", "commandhome", "commandaway", "matchscorehome", "matchscoreaway", "totalfirsttimehome", "totalfirsttimeaway", "homeplayer1", "homeplayer2", "homeplayer3", "homeplayer4", "homeplayer5", "homeplayer6", "homeplayer7", "homeplayer8", "homeplayer9", "homeplayer10", "homeplayer11", "homeplayer12", "homeplayer13", "homeplayer14", "homeplayer15", "homeplayer16", "homeplayer17", "homeplayer18", "awayplayer1", "awayplayer2", "awayplayer3", "awayplayer4", "awayplayer5", "awayplayer6", "awayplayer7", "awayplayer8", "awayplayer9", "awayplayer10", "awayplayer11", "awayplayer12", "awayplayer13", "awayplayer14", "awayplayer15", "awayplayer16", "awayplayer17", "awayplayer18", }; object[] colData = { Convert.ToDateTime(result.Date), result.Stadion, result.Orbitr, result.TrainerHome, result.TrainerAway, result.CommandHome, result.CommandAway, result.MatchScoreHome, result.MatchScoreAway, result.TotalFirstTimeHome, result.TotalFirstTimeAway, result.HomePlayers[0], result.HomePlayers[1], result.HomePlayers[2], result.HomePlayers[3], result.HomePlayers[4], result.HomePlayers[5], result.HomePlayers[6], result.HomePlayers[7], result.HomePlayers[8], result.HomePlayers[9], result.HomePlayers[10], result.HomePlayers[11], result.HomePlayers[12], result.HomePlayers[13], result.HomePlayers[14], result.HomePlayers[15], result.HomePlayers[16], result.HomePlayers[17], result.AwayPlayers[0], result.AwayPlayers[1], result.AwayPlayers[2], result.AwayPlayers[3], result.AwayPlayers[4], result.AwayPlayers[5], result.AwayPlayers[6], result.AwayPlayers[7], result.AwayPlayers[8], result.AwayPlayers[9], result.AwayPlayers[10], result.AwayPlayers[11], result.AwayPlayers[12], result.AwayPlayers[13], result.AwayPlayers[14], result.AwayPlayers[15], result.AwayPlayers[16], result.AwayPlayers[17], }; mainTable.addRow(colName, colData); if (result.ReplacePlayers.Count() > 0) { foreach (string[] tmp in result.ReplacePlayers) { string[] name = { "parentid", "time", "playerout", "playerin", "command", }; object[] data = { id, tmp[1], tmp[2], tmp[3], tmp[0], }; replaceTable.addRow(name, data); } } if (result.YCard.Count() > 0) { foreach (string[] tmp in result.YCard) { string[] name = { "parentid", "time", "player", "command", }; object[] data = { id, tmp[1], tmp[2], tmp[0], }; yTable.addRow(name, data); } } if (result.RCard.Count() > 0) { foreach (string[] tmp in result.RCard) { string[] name = { "parentid", "time", "player", "command", }; object[] data = { id, tmp[1], tmp[2], tmp[0], }; rTable.addRow(name, data); } } if (result.Ball.Count() > 0) { foreach (string[] tmp in result.Ball) { string[] name = { "parentid", "time", "player", "pass", "command", }; object[] data = { id, tmp[1], tmp[2], tmp[3], tmp[0], }; ballTable.addRow(name, data); } } if (result.AutoBall.Count() > 0) { foreach (string[] tmp in result.AutoBall) { string[] name = { "parentid", "time", "player", "command", "pass", }; object[] data = { id, tmp[1], tmp[2], tmp[3], tmp[0], }; autoballTable.addRow(name, data); } } int b = 0; if (result.Stats.Count() > 0) { foreach (string[] tmp in result.Stats) { string[] name = { "parentid", "name", "home", "away", }; object[] data = { id, tmp[0], tmp[1], tmp[2], }; statsTable.addRow(name, data); } } ++id; } }
private void StartParse() { do { Browser.Url = $"https://www.scoreboard.com/ru/match/{matches[curMatch]}/#match-summary"; string link = $"https://www.scoreboard.com/ru/match/{matches[curMatch]}/#match-summary"; System.Threading.Thread.Sleep(3000); page2 = Browser.GetHtml();//ParserSites.GetPage(link); link = $"https://d.scoreboard.com/ru/x/feed/d_li_{matches[curMatch]}_ru_1"; page2 += ParserSites.GetPage2(link); link = $"https://d.scoreboard.com/ru/x/feed/d_st_{matches[curMatch]}_ru_1"; page2 += ParserSites.GetPage2(link); ++curMatch; if (curMatch > 0) { MatchState result = new MatchState(); result = ParserSites.GetMatch(page2); string[] colName = { "date", "stadion", "orbitr", "trainerhome", "traineraway", "commandhome", "commandaway", "matchscorehome", "matchscoreaway", "totalfirsttimehome", "totalfirsttimeaway", "homeplayer1", "homeplayer2", "homeplayer3", "homeplayer4", "homeplayer5", "homeplayer6", "homeplayer7", "homeplayer8", "homeplayer9", "homeplayer10", "homeplayer11", "homeplayer12", "homeplayer13", "homeplayer14", "homeplayer15", "homeplayer16", "homeplayer17", "homeplayer18", "awayplayer1", "awayplayer2", "awayplayer3", "awayplayer4", "awayplayer5", "awayplayer6", "awayplayer7", "awayplayer8", "awayplayer9", "awayplayer10", "awayplayer11", "awayplayer12", "awayplayer13", "awayplayer14", "awayplayer15", "awayplayer16", "awayplayer17", "awayplayer18", }; object[] colData = { Convert.ToDateTime(result.Date), result.Stadion, result.Orbitr, result.TrainerHome, result.TrainerAway, result.CommandHome, result.CommandAway, result.MatchScoreHome, result.MatchScoreAway, result.TotalFirstTimeHome, result.TotalFirstTimeAway, result.HomePlayers[0], result.HomePlayers[1], result.HomePlayers[2], result.HomePlayers[3], result.HomePlayers[4], result.HomePlayers[5], result.HomePlayers[6], result.HomePlayers[7], result.HomePlayers[8], result.HomePlayers[9], result.HomePlayers[10], result.HomePlayers[11], result.HomePlayers[12], result.HomePlayers[13], result.HomePlayers[14], result.HomePlayers[15], result.HomePlayers[16], result.HomePlayers[17], result.AwayPlayers[0], result.AwayPlayers[1], result.AwayPlayers[2], result.AwayPlayers[3], result.AwayPlayers[4], result.AwayPlayers[5], result.AwayPlayers[6], result.AwayPlayers[7], result.AwayPlayers[8], result.AwayPlayers[9], result.AwayPlayers[10], result.AwayPlayers[11], result.AwayPlayers[12], result.AwayPlayers[13], result.AwayPlayers[14], result.AwayPlayers[15], result.AwayPlayers[16], result.AwayPlayers[17], }; mainTable.addRow(colName, colData); if (result.ReplacePlayers.Count() > 0) { foreach (string[] tmp in result.ReplacePlayers) { string[] name = { "parentid", "time", "playerout", "playerin", "command", }; object[] data = { id, tmp[1], tmp[2], tmp[3], tmp[0], }; replaceTable.addRow(name, data); } } if (result.YCard.Count() > 0) { foreach (string[] tmp in result.YCard) { string[] name = { "parentid", "time", "player", "command", }; object[] data = { id, tmp[1], tmp[2], tmp[0], }; yTable.addRow(name, data); } } if (result.RCard.Count() > 0) { foreach (string[] tmp in result.RCard) { string[] name = { "parentid", "time", "player", "command", }; object[] data = { id, tmp[1], tmp[2], tmp[0], }; rTable.addRow(name, data); } } if (result.Ball.Count() > 0) { foreach (string[] tmp in result.Ball) { string[] name = { "parentid", "time", "player", "command", "pass", }; object[] data = { id, tmp[1], tmp[2], tmp[3], tmp[0], }; ballTable.addRow(name, data); } } if (result.AutoBall.Count() > 0) { foreach (string[] tmp in result.AutoBall) { string[] name = { "parentid", "time", "player", "command", }; object[] data = { id, tmp[1], tmp[2], tmp[0], }; autoballTable.addRow(name, data); } } int b = 0; if (result.Stats.Count() > 0) { foreach (string[] tmp in result.Stats) { string[] name = { "parentid", "name", "home", "away", }; object[] data = { id, tmp[0], tmp[1], tmp[2], }; statsTable.addRow(name, data); } } ++id; } --counter; label1.BeginInvoke((MethodInvoker)(() => label1.Text = counter.ToString())); } while (int.Parse(label1.Text) >= curMatch); }
public static MatchState GetMatch(string page) { HtmlParser htmlParser = new HtmlParser(); var parsePage = htmlParser.ParseDocument(page); MatchState matchState = new MatchState(); List <string> score = new List <string>(); matchState.Date = parsePage.QuerySelector("div.description__time").TextContent.Split(' ')[0]; matchState.TrainerHome = parsePage.QuerySelector("table#coaches>tbody>tr.odd>td.fl").TextContent.Trim(); matchState.TrainerAway = parsePage.QuerySelector("table#coaches>tbody>tr.odd>td.fr").TextContent.Trim(); matchState.CommandHome = parsePage.QuerySelector("div.team-text.tname-home>div.tname>div.tname__text>a.participant-imglink").TextContent; matchState.CommandAway = parsePage.QuerySelector("div.team-text.tname-away>div.tname>div.tname__text>a.participant-imglink").TextContent; matchState.MatchScoreHome = parsePage.QuerySelectorAll("span.scoreboard")[0].TextContent; matchState.MatchScoreAway = parsePage.QuerySelectorAll("span.scoreboard")[1].TextContent; //орбитр и стадион string[] matchInfo = new string[3]; int infoCount = 0; foreach (var HomePlayers in parsePage.QuerySelectorAll("div.match-information-data>div.content")) { matchInfo[infoCount] = HomePlayers.TextContent; ++infoCount; } matchState.Orbitr = matchInfo[0].Substring(matchInfo[0].IndexOf(":") + 1, (matchInfo[0].IndexOf(".") - matchInfo[0].IndexOf(":"))); matchState.Stadion = matchInfo[2].Substring(matchInfo[2].IndexOf(":") + 1, (matchInfo[2].IndexOf("(") - matchInfo[2].IndexOf(":") - 2)); //состав команд foreach (var HomePlayers in parsePage.QuerySelectorAll("td.fl>div.name>a")) { if (matchState.HomePlayers.Count > 17) { break; } matchState.HomePlayers.Add(HomePlayers.TextContent.Replace("(C)", "").Replace("(В)", "").Trim()); } foreach (var AwayPlayers in parsePage.QuerySelectorAll("td.fr>div.name>a")) { if (matchState.AwayPlayers.Count > 17) { break; } matchState.AwayPlayers.Add(AwayPlayers.TextContent.Replace("(C)", "").Replace("(В)", "").Trim()); } #region Замены // замены дома foreach (var HomeReplays in parsePage.QuerySelectorAll("td.fl>div.icon-lineup>span.substitution-out")) { //77' Вуд К. (Крауч П.) var tmp = HomeReplays.Parent; string title = (tmp as AngleSharp.Html.Dom.IHtmlDivElement).Title; int index = title.IndexOf("'"); string replace = title.Substring(0, index); string names = title.Substring(index + 2, title.Length - index - 2); int a = 0, b = 0; if (replace.IndexOf("+") > 0) { index = replace.IndexOf("+"); a = int.Parse(replace.Substring(0, index)); b = int.Parse(replace.Substring(index + 1, replace.Length - index - 1)); replace = (a + b).ToString(); } else { a = int.Parse(replace); } if (a > 45) { continue; } else { string[] Replace = new string[4]; Replace[0] = matchState.CommandHome; Replace[1] = replace; //"Мавропанос К. (Косьельни Л.)" Replace[2] = (names.Substring(0, names.IndexOf("(") - 1)); Replace[3] = (names.Substring(names.IndexOf("(") + 1, (names.IndexOf(")") - names.IndexOf("(") - 1))); matchState.ReplacePlayers.Add(Replace); } } //Замены гости foreach (var HomeReplays in parsePage.QuerySelectorAll("td.fr>div.icon-lineup>span.substitution-out")) { //77' Вуд К. (Крауч П.) var tmp = HomeReplays.Parent; string title = (tmp as AngleSharp.Html.Dom.IHtmlDivElement).Title; int index = title.IndexOf("'"); string replace = title.Substring(0, index); string names = title.Substring(index + 2, title.Length - index - 2); int a = 0, b = 0; if (replace.IndexOf("+") > 0) { index = replace.IndexOf("+"); a = int.Parse(replace.Substring(0, index)); b = int.Parse(replace.Substring(index + 1, replace.Length - index - 1)); replace = (a + b).ToString(); } else { a = int.Parse(replace); } if (a > 45) { continue; } else { string[] Replace = new string[4]; Replace[0] = matchState.CommandAway; Replace[1] = replace; //"Мавропанос К. (Косьельни Л.)" Replace[2] = (names.Substring(0, names.IndexOf("(") - 1)); Replace[3] = (names.Substring(names.IndexOf("(") + 1, (names.IndexOf(")") - names.IndexOf("(") - 1))); matchState.ReplacePlayers.Add(Replace); } } #endregion #region желтые карты // желтые карты дома foreach (var HomeReplays in parsePage.QuerySelectorAll("td.fl>div.icon-lineup>span.y-card")) { //77' Вуд К. (Крауч П.) var tmp = HomeReplays.Parent; string title = (tmp as AngleSharp.Html.Dom.IHtmlDivElement).Title; int index = title.IndexOf("'"); string time = title.Substring(0, index); string card = title.Substring(index + 2, title.Length - index - 2); int a = 0, b = 0; if (time.IndexOf("+") > 0) { index = time.IndexOf("+"); a = int.Parse(time.Substring(0, index)); b = int.Parse(time.Substring(index + 1, time.Length - index - 1)); time = (a + b).ToString(); } else { a = int.Parse(time); } if (a > 45) { continue; } else { string[] Card = new string[3]; Card[0] = matchState.CommandHome; Card[1] = time; Card[2] = card.Replace("(C)", "").Replace("(В)", "").Trim(); matchState.YCard.Add(Card); } } //желтые карты гость foreach (var HomeReplays in parsePage.QuerySelectorAll("td.fr>div.icon-lineup>span.y-card")) { var tmp = HomeReplays.Parent; string title = (tmp as AngleSharp.Html.Dom.IHtmlDivElement).Title; int index = title.IndexOf("'"); string time = title.Substring(0, index); string card = title.Substring(index + 2, title.Length - index - 2); int a = 0, b = 0; if (time.IndexOf("+") > 0) { index = time.IndexOf("+"); a = int.Parse(time.Substring(0, index)); b = int.Parse(time.Substring(index + 1, time.Length - index - 1)); time = (a + b).ToString(); } else { a = int.Parse(time); } if (a > 45) { continue; } else { string[] Card = new string[3]; Card[0] = matchState.CommandAway; Card[1] = time; Card[2] = card.Replace("(C)", "").Replace("(В)", "").Trim(); matchState.YCard.Add(Card); } } #endregion #region красные карты // красные карты дома foreach (var HomeReplays in parsePage.QuerySelectorAll("td.fl>div.icon-lineup>span.r-card")) { //77' Вуд К. (Крауч П.) var tmp = HomeReplays.Parent; string title = (tmp as AngleSharp.Html.Dom.IHtmlDivElement).Title; int index = title.IndexOf("'"); string time = title.Substring(0, index); string card = title.Substring(index + 2, title.Length - index - 2); int a = 0, b = 0; if (time.IndexOf("+") > 0) { index = time.IndexOf("+"); a = int.Parse(time.Substring(0, index)); b = int.Parse(time.Substring(index + 1, time.Length - index - 1)); time = (a + b).ToString(); } else { a = int.Parse(time); } if (a > 45) { continue; } else { string[] Card = new string[3]; Card[0] = matchState.CommandHome; Card[1] = time; Card[2] = card; matchState.RCard.Add(Card); } } //красные карты гость foreach (var HomeReplays in parsePage.QuerySelectorAll("td.fr>div.icon-lineup>span.r-card")) { var tmp = HomeReplays.Parent; string title = (tmp as AngleSharp.Html.Dom.IHtmlDivElement).Title; int index = title.IndexOf("'"); string time = title.Substring(0, index); string card = title.Substring(index + 2, title.Length - index - 2); int a = 0, b = 0; if (time.IndexOf("+") > 0) { index = time.IndexOf("+"); a = int.Parse(time.Substring(0, index)); b = int.Parse(time.Substring(index + 1, time.Length - index - 1)); time = (a + b).ToString(); } else { a = int.Parse(time); } if (a > 45) { continue; } else { string[] Card = new string[3]; Card[0] = matchState.CommandAway; Card[1] = time; Card[2] = card; matchState.RCard.Add(Card); } } #endregion #region мячи // мячи дома foreach (var HomeReplays in parsePage.QuerySelectorAll("td.fl>div.icon-lineup>span.soccer-ball")) { //77' Вуд К. (Крауч П.) var tmp = HomeReplays.Parent; string title = (tmp as AngleSharp.Html.Dom.IHtmlDivElement).Title; int index = title.IndexOf("'"); string time = title.Substring(0, index); string names = title.Substring(index + 2, title.Length - index - 2); int a = 0, b = 0; if (time.IndexOf("+") > 0) { index = time.IndexOf("+"); a = int.Parse(time.Substring(0, index)); b = int.Parse(time.Substring(index + 1, time.Length - index - 1)); time = (a + b).ToString(); } else { a = int.Parse(time); } if (a > 45) { continue; } else { string[] Ball = new string[4]; Ball[0] = matchState.CommandHome; Ball[1] = time; if (names.IndexOf("(") >= 0) { Ball[2] = (names.Substring(0, names.IndexOf("(") - 1)); Ball[3] = (names.Substring(names.IndexOf("(") + 1, (names.IndexOf(")") - names.IndexOf("(") - 1))); } else { Ball[2] = names.Trim(); Ball[3] = ""; } matchState.Ball.Add(Ball); matchState.TotalFirstTimeHome = (int.Parse(matchState.TotalFirstTimeHome) + 1).ToString(); } } //мячи гость foreach (var HomeReplays in parsePage.QuerySelectorAll("td.fr>div.icon-lineup>span.soccer-ball")) { var tmp = HomeReplays.Parent; string title = (tmp as AngleSharp.Html.Dom.IHtmlDivElement).Title; int index = title.IndexOf("'"); string time = title.Substring(0, index); string names = title.Substring(index + 2, title.Length - index - 2); int a = 0, b = 0; if (time.IndexOf("+") > 0) { index = time.IndexOf("+"); a = int.Parse(time.Substring(0, index)); b = int.Parse(time.Substring(index + 1, time.Length - index - 1)); time = (a + b).ToString(); } else { a = int.Parse(time); } if (a > 45) { continue; } else { string[] Ball = new string[4]; Ball[0] = matchState.CommandHome; Ball[1] = time; if (names.IndexOf("(") >= 0) { Ball[2] = (names.Substring(0, names.IndexOf("(") - 1)); Ball[3] = (names.Substring(names.IndexOf("(") + 1, (names.IndexOf(")") - names.IndexOf("(") - 1))); } else { Ball[2] = names.Trim(); Ball[3] = ""; } matchState.Ball.Add(Ball); matchState.TotalFirstTimeAway = (int.Parse(matchState.TotalFirstTimeAway) + 1).ToString(); } } #endregion #region автогол // автогол дома foreach (var HomeReplays in parsePage.QuerySelectorAll("td.fl>div.icon-lineup>span.soccer-ball-own")) { var tmp = HomeReplays.Parent; string title = (tmp as AngleSharp.Html.Dom.IHtmlDivElement).Title; int index = title.IndexOf("'"); string time = title.Substring(0, index); string names = title.Substring(index + 2, title.Length - index - 2); int a = 0, b = 0; if (time.IndexOf("+") > 0) { index = time.IndexOf("+"); a = int.Parse(time.Substring(0, index)); b = int.Parse(time.Substring(index + 1, time.Length - index - 1)); time = (a + b).ToString(); } else { a = int.Parse(time); } if (a > 45) { continue; } else { string[] AutoBall = new string[3]; AutoBall[0] = matchState.CommandHome; AutoBall[1] = time; AutoBall[2] = names.Trim(); matchState.AutoBall.Add(AutoBall); matchState.TotalFirstTimeAway = (int.Parse(matchState.TotalFirstTimeAway) + 1).ToString(); } } //автогол гость foreach (var HomeReplays in parsePage.QuerySelectorAll("td.fr>div.icon-lineup>span.soccer-ball-own")) { var tmp = HomeReplays.Parent; string title = (tmp as AngleSharp.Html.Dom.IHtmlDivElement).Title; int index = title.IndexOf("'"); string time = title.Substring(0, index); string names = title.Substring(index + 2, title.Length - index - 2); int a = 0, b = 0; if (time.IndexOf("+") > 0) { index = time.IndexOf("+"); a = int.Parse(time.Substring(0, index)); b = int.Parse(time.Substring(index + 1, time.Length - index - 1)); time = (a + b).ToString(); } else { a = int.Parse(time); } if (a > 45) { continue; } else { string[] AutoBall = new string[3]; AutoBall[0] = matchState.CommandHome; AutoBall[1] = time; AutoBall[2] = names.Trim(); matchState.AutoBall.Add(AutoBall); matchState.TotalFirstTimeHome = (int.Parse(matchState.TotalFirstTimeHome) + 1).ToString(); } } #endregion #region статистика foreach (var HomeReplays in parsePage.QuerySelectorAll("div#tab-statistics-1-statistic>div.statRow>div.statTextGroup")) { //37%Владение мячом63% string doc = HomeReplays.InnerHtml; HtmlParser htmlPar = new HtmlParser(); var parseContent = htmlPar.ParseDocument(doc); string[] stats = new string[3]; stats[1] = parseContent.QuerySelector("div.statText--homeValue").TextContent.Trim('%'); stats[0] = parseContent.QuerySelector("div.statText--titleValue").TextContent; stats[2] = parseContent.QuerySelector("div.statText--awayValue").TextContent.Trim('%'); matchState.Stats.Add(stats); } #endregion return(matchState); }