Exemplo n.º 1
0
        private async Task GetSTSQData()
        {
            //CefWebBrowserControl.ClickButtonByJsPath(chromiumWebBrowser, @"document.querySelector('div.tool-bar').children[6].click()");
            int topic_index = 0;

            while (!cts.Token.IsCancellationRequested)
            {
                topic_index++;
                var topic_type = string.Empty;
                var topic      = string.Empty;
                try
                {
                    await Task.Delay(300);

                    string html = await CefWebBrowserControl.GetHtmlSource(chromiumWebBrowser);

                    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                    doc.LoadHtml(html);                    //html字符串
                    //获取标签里的值select-left pull-left options-w

                    var enable = doc.DocumentNode.SelectSingleNode("//div[@class='btn_ct tb']/button[2]");
                    if (enable.Attributes["disabled"] != null && enable.Attributes["disabled"].Value.Equals("disabled"))
                    {
                        break;
                    }

                    topic_type = doc.DocumentNode.SelectSingleNode("//div[@class='test_style']").InnerText.Split(new char[2] {
                        '【', '】'
                    })[1];
                    //topic_index = doc.DocumentNode.SelectSingleNode("//span[@class='topic-type']/following-sibling::span").InnerText.Replace("\\n", "").Split('/')[1];
                    topic = doc.DocumentNode.SelectSingleNode("//div[@class='test_title']/span").InnerHtml;

                    if ("单选题 多选题 判断题 不定项选择题 排序题 单项选择题 多项选择题".Contains(topic_type))
                    {
                        var answers = doc.DocumentNode.SelectNodes("//div[@class='test_bot']/dl");

                        CefWebBrowserControl.ClickButtonByJsPath(chromiumWebBrowser, @"document.querySelector('div.test_bot').children[0].children[0].click()");
                        await Task.Delay(200);

                        listBox1.Items.Add($"[{ topic_type}]");
                        listBox1.Items.Add($"{topic_index}、{topic}");
                        foreach (var item in answers)
                        {
                            string value1 = item.SelectSingleNode("./span").InnerText;
                            string value2 = item.InnerText;

                            listBox1.Items.Add($"{value1}{value2}");
                        }
                    }

                    var answerRight    = doc.DocumentNode.SelectSingleNode("//span[@class='rightAnswer']").InnerText;
                    var answerAnalysis = doc.DocumentNode.SelectSingleNode("//div[@class='answerText']/div[4]").InnerHtml;
                    listBox1.Items.Add("答案:" + answerRight);
                    listBox1.Items.Add(answerAnalysis);

                    CefWebBrowserControl.ClickButtonByJsPath(chromiumWebBrowser, @"document.querySelector('div.test_bot').lastElementChild.firstElementChild.click()");
                }
                catch (Exception ex)
                {
                    listBox1.Items.Add($"错误行:{topic_type},{topic_index},{topic}");
                    cts?.Cancel();
                    break;
                }
            }
        }
Exemplo n.º 2
0
        private async Task GetKSBData()
        {
            CefWebBrowserControl.ClickButtonByJsPath(chromiumWebBrowser, @"document.querySelector('div.tool-bar').children[6].click()");
            int topic_index = 0;
            var topic_type  = string.Empty;

            while (!cts.Token.IsCancellationRequested)
            {
                topic_index++;
                //var topic_type = string.Empty;
                var topic = string.Empty;
                try
                {
                    await Task.Delay(500);

                    string html = await CefWebBrowserControl.GetHtmlSource(chromiumWebBrowser);

                    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                    doc.LoadHtml(html);                    //html字符串
                    //获取标签里的值select-left pull-left options-w

                    var new_type = doc.DocumentNode.SelectSingleNode("//span[@class='topic-type']").InnerText;
                    //topic_index = doc.DocumentNode.SelectSingleNode("//span[@class='topic-type']/following-sibling::span").InnerText.Replace("\\n", "").Split('/')[1];
                    topic = doc.DocumentNode.SelectSingleNode("//div[@class='qusetion-box']").InnerHtml;

                    if (topic_type != new_type)
                    {
                        topic_type = new_type;
                        listBox1.Items.Add($"[{ topic_type}]");
                    }
                    listBox1.Items.Add($"{topic_index}.{topic}");

                    if ("单选题 多选题 判断题 不定项选择题 排序题".Contains(topic_type))
                    {
                        var answers = doc.DocumentNode.SelectNodes("//div[@class='option']");
                        if (answers != null)
                        {
                            foreach (var item in answers)
                            {
                                string value1 = item.SelectNodes("./span")[0].InnerText;
                                string value2 = item.SelectNodes("./span")[1].InnerText;

                                listBox1.Items.Add($"{value1}{value2};");
                            }
                        }
                        else
                        {
                            listBox2.Items.Add($"{topic_index}.题目错误");
                        }
                    }

                    var answerRight    = doc.DocumentNode.SelectSingleNode("//p[@class='answer-right']/span").InnerText;
                    var answerAnalysis = doc.DocumentNode.SelectSingleNode("//p[@class='answer-analysis']").InnerHtml;
                    if (checkBox1.Checked)
                    {
                        listBox2.Items.Add($"{topic_index}.{answerRight}");
                    }
                    else
                    {
                        listBox1.Items.Add("答案:" + answerRight);
                        listBox1.Items.Add(answerAnalysis);
                    }


                    var enable = doc.DocumentNode.SelectSingleNode("//div[@class='next-preve']/button[2]");
                    if (enable.Attributes["disabled"] != null && enable.Attributes["disabled"].Value.Equals("disabled"))
                    {
                        break;
                    }

                    CefWebBrowserControl.ClickButtonByJsPath(chromiumWebBrowser, @"document.querySelector('div.next-preve').children[1].click()");
                }
                catch (Exception ex)
                {
                    listBox1.Items.Add($"错误行:{topic_type},{topic_index},{topic}");
                    cts?.Cancel();
                    break;
                }
            }

            button4_Click(null, null);
        }