internal Bet ParseBet(IHtmlDocument doc, Bet bet)
        {
            var groupe = doc.QuerySelector("a.sport-category-label");

            if (groupe == null)
            {
                throw new ArgumentException($"{nameof(groupe)}==null");
            }
            bet.Groupe    = groupe.TextContent;
            bet.SportType = SportTypeHelper.Parse(bet.Groupe);


            var stakes = doc.QuerySelectorAll("span.selection-link");

            if (bet.SportType == SportType.Футбол)
            {
                MarafonParserHelper.Football(stakes, bet);
            }
            else if (bet.SportType == SportType.Хоккей)
            {
                MarafonParserHelper.Hockey(stakes, bet);
            }
            else if (bet.SportType == SportType.Баскетбол)
            {
                MarafonParserHelper.Backetball(stakes, bet);
            }
            else if (bet.SportType == SportType.Теннис)
            {
                MarafonParserHelper.Tennis(stakes, bet);
            }
            else if (bet.SportType == SportType.Волейбол)
            {
                MarafonParserHelper.Voleyball(stakes, bet);
            }
            else if (bet.SportType == SportType.Гандбол)
            {
                MarafonParserHelper.Ganball(stakes, bet);
            }
            else if (bet.SportType == SportType.Водное_поло)
            {
                MarafonParserHelper.Polo(stakes, bet);
            }
            else
            {
                MarafonParserHelper.CommonTemp(stakes, bet);
            }
            return(bet);
        }
        private void ParsePage(string id)
        {
            HttpRequest req = new HttpRequest
            {
                CharacterSet = Encoding.UTF8,
                UserAgent    = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36 OPR/42.0.2393.94"
            };

            if (UsingProxy)
            {
                req.Proxy = ProxyClient.Parse(ProxyList.GetRnd());
                req.Proxy.ReadWriteTimeout = 1500;
                req.Proxy.ConnectTimeout   = 1500;
            }
            RequestParams requestParams = new RequestParams()
            {
                ["ajax"] = "main",
                ["data"] = $"4|{id}",
            };

            string response = req.Post($"{_url}", requestParams).ToString();
            string data     = response.Remove(response.Length - 2).Remove(0, 9);
            var    json     = JObject.Parse(response);

            HtmlParser parser = new HtmlParser();
            var        doc    = parser.Parse(json["text"].ToString());
            Bet        bet    = new Bet();

            bet.Bookmaker = BookmakerType.BaltBet;
            bet.Site      = "B";

            var maintable = doc.Body.Children[2];
            // HtmlNode mainTable = doc.DocumentNode.ChildNodes[0].ChildNodes[0].ChildNodes[0].ChildNodes[1].ChildNodes[0];
            var groupe = maintable.Children[0].Children[0].TextContent.Split('.')[1].Trim();

            bet.SportType = SportTypeHelper.Parse(groupe);

            var teams =
                maintable.Children[1].Children[1].Children[0].Children[3].TextContent.Split('-');
        }
        public List <Bet> Parse()
        {
            Bets.Clear();
            _req.CharacterSet = Encoding.UTF8;
            _req.UserAgent    = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36";

            //_req.Proxy=ProxyClient.Parse(ProxyType.Http,"127.0.0.1:8888");



            Stopwatch sw = new Stopwatch();

            sw.Start();

            if (_fonbetClient == null)
            {
                _fonbetClient = new FonbetClient(_url);
                _fonbetClient.Start();
            }


            var line = _fonbetClient.GetLine();



            List <Bet> rez      = new List <Bet>();
            var        lastTime = (DateTime.Now - line.LastUpdate).TotalMilliseconds;

            if (lastTime > MainConfigurate.Configurate.FonbetMaxTime)
            {
                Logger.AddLog($"Последний раз обновляли линию {lastTime} мс назад. Это долго", Logger.LogTarget.Fonbet, Logger.LogLevel.Warn);
            }
            else
            {
                foreach (KeyValuePair <int, Event> @event in line.Events)
                {
                    var ev = @event.Value;

                    if (ev.IsBlock)
                    {
                        continue;
                    }
                    if (ev.Level != 1)
                    {
                        continue;
                    }

                    string team1     = ev.Team1;
                    string team2     = ev.Team2;
                    string sportName = line.Sports[ev.SportId].Name;

                    /*
                     *
                     * 974,1809,1812,1815       \   Итб1
                     * 976,1810,1813,1816       /   Итм1
                     *
                     * 978,1854,1873,1880       \   Итб2
                     * 980,1871,1874,1881       /   Итм2
                     *
                     * */


                    Bet bet = new Bet
                    {
                        URL       = "live/?locale=ru#" + ev.Id,
                        Bookmaker = BookmakerType.Fonbet,
                        Team1     = team1,
                        Team2     = team2
                    };

                    if (ev.Team1Id == -1)
                    {
                        continue;
                    }
                    if (ev.Team2Id == -1)
                    {
                        continue;
                    }
                    bet.Team1Id = ev.Team1Id;
                    bet.Team2Id = ev.Team2Id;


                    IBTBet ibt1 = new IBTBet();
                    IBTBet ibt2 = new IBTBet();
                    ibt1.TeamName = bet.Team1;
                    ibt2.TeamName = bet.Team2;

                    bet.SportType = SportTypeHelper.Parse(sportName);

                    bet.Groupe = sportName.Split('.')[0].Trim();
                    bet.Name   = team1 + " - " + team2;
                    bet.Site   = "F";

                    bet = SetEvents(bet, ev);
                    if (bet == null)
                    {
                        continue;
                    }


                    if (ev.Factors.ContainsKey(974))
                    {
                        if (!ev.Factors[974].IsBlocked)
                        {
                            ibt1.Tmax  = ev.Factors[974].V;
                            ibt1.Tmaxo = ev.Factors[974].E + "f974,974," + ev.Id;
                        }
                    }
                    if (ev.Factors.ContainsKey(976))
                    {
                        if (!ev.Factors[976].IsBlocked)
                        {
                            ibt1.Tmin  = ev.Factors[976].V;
                            ibt1.Tmino = ev.Factors[976].E + "f976,976," + ev.Id;
                            ibt1.Coeff = SetValue(ev.Factors[976].Pt);
                        }
                    }

                    if (ev.Factors.ContainsKey(978))
                    {
                        if (!ev.Factors[978].IsBlocked)
                        {
                            ibt2.Tmax  = ev.Factors[978].V;
                            ibt2.Tmaxo = ev.Factors[978].E + "f978,978," + ev.Id;
                            ibt2.Coeff = SetValue(ev.Factors[978].Pt);
                        }
                    }
                    if (ev.Factors.ContainsKey(980))
                    {
                        if (!ev.Factors[980].IsBlocked)
                        {
                            ibt2.Tmin  = ev.Factors[980].V;
                            ibt2.Tmino = ev.Factors[980].E + "f980,980," + ev.Id;
                        }
                    }


                    if (ibt1.Isvalid())
                    {
                        bet.IBTList.Add(ibt1);
                    }
                    if (ibt2.Isvalid())
                    {
                        bet.IBTList.Add(ibt2);
                    }

                    //Достаем список доп. таймов к матчу
                    List <Event> times = line.GetAdditionTime(ev.Id);
                    foreach (Event time in times)
                    {
                        Bet betmini = bet.ShortCopy();
                        betmini = SetEvents(betmini, time, false);
                        if (betmini == null)
                        {
                            continue;
                        }

                        if (betmini.Games.Count != 0)
                        {
                            bet.Games.AddRange(betmini.Games);
                            betmini.Games.Clear();
                        }

                        Regex  reg      = new Regex("(.-)");
                        Match  match    = reg.Match(time.Name);
                        string partData = match.Value.Split('-').First();
                        if (time.Name.Contains("пол"))
                        {
                            partData = "1" + partData;
                        }

                        SportTimePart part = SportTimePartHelper.Parse(partData);
                        if (part == SportTimePart.Nan)
                        {
                            continue;
                        }
                        bet.Parts.Add(part, betmini);
                    }

                    rez.Add(bet);
                }
            }


            sw.Stop();
            if (sw.ElapsedMilliseconds < 1000)
            {
                Thread.Sleep(1000 - (int)sw.ElapsedMilliseconds);
            }
            Logger.AddLog($"Fonbet parse: {sw.Elapsed} мс. ставок: {rez.Count}; всего ставок: {line.Events.Count}", Logger.LogTarget.Fonbet);
            return(rez);
        }
        private Bet ParsePage(string href)
        {
#if DEBUGPAGE
            Stopwatch sw = new Stopwatch();
            sw.Start();
#endif
            HttpRequest req = new HttpRequest
            {
                CharacterSet = Encoding.GetEncoding(1251),
                UserAgent    =
                    "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36 OPR/42.0.2393.94"
            };
            if (UsingProxy)
            {
                req.Proxy = ProxyClient.Parse(ProxyList.GetRnd());
                req.Proxy.ConnectTimeout   = 1500;
                req.Proxy.ReadWriteTimeout = 1500;
            }

            var response = req.Get($"{_url}{href}").ToString();

            HtmlParser parser = new HtmlParser();

            IHtmlDocument document = parser.Parse(response);
            IElement      oddsList = document.GetElementById("oddsList");
            Bet           bet      = new Bet
            {
                Bookmaker = BookmakerType.Parimatch,
                Site      = "P",
                SportType = SportTypeHelper.Parse(oddsList.Children[0].ChildNodes[1].ChildNodes[2].TextContent),
                Groupe    = oddsList.Children[0].ChildNodes[1].ChildNodes[2].TextContent,
                Time      = "0",
                URL       = href
            };


            List <IElement> tables = document.QuerySelectorAll("div#oddsList div.wrapper > table > tbody").ToList();
            if (tables == null)
            {
                throw new ArgumentNullException("Parimatch: Ошибка получения таблицы со ставками");
            }

            IElement table = tables[1].Children.FirstOrDefault();
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }



            //тупая система. Иногда есть картинка между командами
            //иногда команды обернуты в доп. теги
            bet.Team1 = table.Children[1].ChildNodes[0].TextContent;
            if (bet.Team1.Contains("угловые"))
            {
                throw new ArgumentException("Parimatch: статика");
            }
            for (int i = 1; i < table.Children[1].ChildNodes.Length; i++)
            {
                if (!String.IsNullOrWhiteSpace(table.Children[1].ChildNodes[i].TextContent))
                {
                    bet.Team2 = table.Children[1].ChildNodes[i].TextContent;
                    break;
                }
            }

            bet.Name = bet.Team1 + " - " + bet.Team2;
            //получаем заголовок таблицы
            //и таблицу
            IElement tableHeader   = tables[0].Children.FirstOrDefault();
            IElement tableMainDesc = tables[1].Children.FirstOrDefault();

            if (tableMainDesc != null)
            {
                tableMainDesc = FixTable(tableMainDesc);
            }


            if (tableHeader == null ||
                tableMainDesc == null ||
                tableHeader.ChildElementCount != tableMainDesc.ChildElementCount)
            {
                throw new ArgumentException("Parimatch main table is corrupt");
            }


            ParseBet(bet, tableHeader, tableMainDesc);



            if (tables.Count == 3)
            {
                IHtmlCollection <IElement> dopTables =
                    tables[2].Children.Where(x => x.Attributes["class"] != null && x.Attributes["class"].Value == "bk")
                    .ToCollection();

                for (int i = 0; i < dopTables.Length; i++)
                {
                    var dopTable = dopTables[i];

                    if (dopTable.TextContent.Contains("Прием ставок приостановлен"))
                    {
                        continue;
                    }
                    dopTable = FixTable(dopTable);
                    if (dopTable.ChildElementCount != tableHeader.ChildElementCount)
                    {
                        throw new ArgumentException();
                    }

                    var dopBet = bet.ShortCopy();

                    var t = dopTable.Children[1].TextContent.Split('-').First();
                    if (dopBet.SportType == SportType.Баскетбол)
                    {
                        if (dopTable.Children[1].TextContent.Contains("половина"))
                        {
                            if (dopTable.Children[1].TextContent.Contains("Первая половина:"))
                            {
                                t = "11";
                            }
                            else if (dopTable.Children[1].TextContent.Contains("Вторая половина:"))
                            {
                                t = "12";
                            }
                        }
                    }

                    var timePart = SportTimePartHelper.Parse(t);

                    if (timePart == SportTimePart.Nan)
                    {
                        continue;
                    }

                    ParseBet(dopBet, tableHeader, dopTable);
                    bet.Parts[timePart] = dopBet;
                }



                if (bet.SportType == SportType.Теннис)
                {
                    foreach (IElement tr in tables[2].Children)
                    {
                        Regex reg = new Regex("Сет . гейм .: победа");
                        if (reg.IsMatch(tr.TextContent))
                        {
                            var     data  = tr.Children[1].Children[0].TextContent.Split(' ');
                            GameBet gmBet = new GameBet();
                            gmBet.Set        = SportTimePartHelper.Parse(data[1]);
                            gmBet.Team1      = bet.Team1;
                            gmBet.Team2      = bet.Team2;
                            gmBet.GameNumber = (TenisGamePart)Enum.Parse(typeof(TenisGamePart), data[3].Replace(":", ""));
                            gmBet.Coef1      = TryFloatParse(tr.Children[1].Children[1].Children[0].Children.FirstOrDefault()?.Children.FirstOrDefault()?.TextContent);
                            if (gmBet.Coef1 != 0)
                            {
                                gmBet.Coef1o = tr.Children[1].Children[1].Children[0].Children[0].Children[0].Id;
                            }
                            gmBet.Coef2 = TryFloatParse(tr.Children[1].Children[2].Children[0].Children.FirstOrDefault()?.Children.FirstOrDefault()?.TextContent);
                            if (gmBet.Coef2 != 0)
                            {
                                gmBet.Coef2o = tr.Children[1].Children[2].Children[0].Children[0].Children[0].Id;
                            }

                            bet.Games.Add(gmBet);
                        }
                    }
                }
            }



#if DEBUGPAGE
            Console.WriteLine(bet);
            Console.WriteLine($"Parimatch pageparse: {href} {sw.Elapsed} мс");
#endif

            return(bet);
        }