Exemple #1
0
        private static string GetJxsscResult(string drawNo)
        {
            var url = "http://data.shishicai.cn/jxssc/haoma/";

            var driver = new PhantomJSDriver { Url = url };
            driver.Navigate();

            // the driver can now provide you with what you need (it will execute the script)
            // get the source of the page
            var source = driver.PageSource;

            // fully navigate the dom
            var drawResultElements = driver.FindElementByClassName("newNum").FindElements(By.CssSelector("table[class='data_tab'] tbody tr"));
            var result = string.Empty;

            foreach (var draws in drawResultElements)
            {
                var drawElemnet = draws.Text.Split(' ');
                if (drawElemnet[0].Contains(drawNo))
                {
                    result = string.Join(",", drawElemnet.Select(o => o.ToString()).ToArray());
                    break;
                }
            }

            driver.Close();
            return result;
        }
        private void button_Click(object sender, RoutedEventArgs e)
        {
            var driverService = PhantomJSDriverService.CreateDefaultService();
            driverService.HideCommandPromptWindow = true;

            var webDriver = new PhantomJSDriver(driverService);
            webDriver.Navigate().GoToUrl("http://www.udebug.com/UVa/10812");
            IWebElement inputBox = webDriver.FindElement(By.Id("edit-input-data"));
            inputBox.SendKeys("3\n2035415231 1462621774\n1545574401 1640829072\n2057229440 1467906174");
            IWebElement submitButton = webDriver.FindElement(By.Id("edit-output"));
            submitButton.Click();
            string answer = webDriver.PageSource;
            int begin = answer.IndexOf("<pre>") + 5;
            answer = answer.Substring(begin, answer.IndexOf("</pre>") - begin);
            webDriver.Close();
            MessageBox.Show(answer);
        }