Exemplo n.º 1
0
        /// <summary>
        /// Получение данных варианта (все номера)
        /// </summary>
        /// <param name="IDVar">Номер варианта</param>
        /// <returns>Полученные данные</returns>
        private static DatVarHTML GetDataVar(string IDVar)
        {
            HtmlDocument htmlDocument = new HtmlDocument();
            string       HTML         = Function.getHTML(@"https://chem-ege.sdamgia.ru/test?id=" + IDVar);

            htmlDocument.LoadHtml(HTML);
            HtmlNodeCollection htmlNodes  = htmlDocument.DocumentNode.SelectNodes("//input");
            DatVarHTML         datVarHTML = new DatVarHTML();

            datVarHTML.Data = @"timer=153&stat_id=0&test_id=" + IDVar;
            foreach (var Comp in htmlNodes)
            {
                try
                {
                    if (Comp.Attributes["class"].Value == "test_inp" && Comp.Attributes["name"].Value.Contains("answer"))
                    {
                        datVarHTML.Data += "&" + Comp.Attributes["name"].Value + "=";
                        if (Comp.Attributes["name"].Value.Contains('C') || Comp.Attributes["name"].Value.Contains('c'))
                        {
                            datVarHTML.C_part++;
                        }
                        else
                        {
                            datVarHTML.A_Part++;
                        }
                    }
                }
                catch { }
            }
            datVarHTML.Data  = datVarHTML.Data.Replace('c', 'C');
            datVarHTML.Data += "&a=check&is_cr=1%22";
            return(datVarHTML);
        }
Exemplo n.º 2
0
        public static VarOtvet Get(string ID, string Patch, bool C_Part = true, MainF.Messenge messenge = null)
        {
            DatVarHTML datVarHTML = GetDataVar(ID);
            VarOtvet   varOtvet   = new VarOtvet {
                Id = ID, otvet_A_Parts = new List <Otvet_A_Part>(0), otvet_C_Parts = new List <Otvet_C_Part>(0)
            };
            HtmlDocument htmlDocument = new HtmlDocument();

            htmlDocument.LoadHtml(Function.PostHtml(Setting.Url + @"/test", datVarHTML.Data));
            // Получаем Html двух таблиц
            HtmlNodeCollection htmlNodes = htmlDocument.DocumentNode.SelectNodes("//div");
            string             OneTab    = null;
            string             TwoTab    = null;

            foreach (var Elem in htmlNodes)
            {
                try
                {
                    if (Elem.Attributes["style"].Value == "vertical-align:top;margin: 5px;text-align:center; display:inline-block; max-width:300px")
                    {
                        TwoTab = Elem.InnerHtml;
                    }
                    else if (Elem.Attributes["style"].Value == "vertical-align:top;margin: 5px;text-align:center; display:inline-block; max-width:500px")
                    {
                        OneTab = Elem.InnerHtml;
                    }
                    else if (OneTab != null && TwoTab != null)
                    {
                        break;
                    }
                }
                catch { }
            }
            // Парсинг части A
            htmlDocument.LoadHtml(OneTab);
            htmlNodes = htmlDocument.DocumentNode.SelectNodes("//tr");
            foreach (var Component in htmlNodes)
            {
                try
                {
                    if (Component.Attributes["class"].Value == "res_row")
                    {
                        HtmlDocument html = new HtmlDocument();
                        html.LoadHtml(Component.InnerHtml);
                        HtmlNodeCollection nodes = html.DocumentNode.SelectNodes("//td");
                        if (nodes != null)
                        {
                            varOtvet.otvet_A_Parts.Add(new Otvet_A_Part {
                                Num = (uint)(varOtvet.otvet_A_Parts.Count + 1), Resul = nodes[nodes.Count - 1].InnerText
                            });
                        }
                    }
                }
                catch { }
            }
            // Парсинг части C
            Patch = Path.Combine(Patch, varOtvet.Id);
            Directory.CreateDirectory(Patch);
            if (C_Part)
            {
                htmlDocument.LoadHtml(TwoTab);
                htmlNodes = htmlDocument.DocumentNode.SelectNodes("//tr");
                foreach (var Component in htmlNodes)
                {
                    if (Component.Attributes["class"]?.Value == "res_row")
                    {
                        HtmlDocument html = new HtmlDocument();
                        html.LoadHtml(Component.InnerHtml);
                        HtmlNodeCollection nodes = html.DocumentNode.SelectNodes("//td");
                        if (nodes != null)
                        {
                            var Res = Get_C_Part_OneNum(nodes[1].InnerText, Patch, messenge);
                            Res.Num = (uint)(varOtvet.otvet_C_Parts.Count + 1);
                            varOtvet.otvet_C_Parts.Add(Res);
                        }
                    }
                }
            }
            return(varOtvet);
        }