Пример #1
0
 public T LoadDataObject <T>(string dataApiUrl)
 {
     lock (_networkSync)
     {
         if (_phantom != null)
         {
             _phantom.Navigate().GoToUrl($"{BaseUrl}/{dataApiUrl}");
             return(JsonConvert.DeserializeObject <T>(_phantom.FindElementByTagName("body").Text,
                                                      new TimestampJsonConverter(), new BooleanConverter()));
         }
         return(default(T));
     }
 }
Пример #2
0
        public override bool Execute(PhantomJSDriver driver)
        {
            IWebElement element = null;

            switch (Parameters[0])
            {
            case "id":
                element = driver.FindElementById(Parameters[1]);
                break;

            case "class":
                element = driver.FindElementByClassName(Parameters[1]);
                break;

            case "tag":
                element = driver.FindElementByTagName(Parameters[1]);
                break;

            case "text":
                element = driver.FindElementByLinkText(Parameters[1]);
                break;

            case "name":
                element = driver.FindElementByName(Parameters[1]);
                break;

            default:
                return(false);
            }

            //Element not found
            if (element == null)
            {
                return(false);
            }
            try
            {
                element.Click();
                return(true);
            }
            catch (Exception e)
            {
                return(false);
                //Element not clickable
            }
        }
Пример #3
0
 public override bool Execute(PhantomJSDriver driver)
 {
     try
     {
         var passwordBox =
             driver.FindElements(By.TagName("input"))
             .FirstOrDefault(e => e.GetAttribute("type").Contains("password"));
         var userEmailBox =
             driver.FindElements(By.TagName("input"))
             .FirstOrDefault(
                 e =>
                 e.GetAttribute("type").Contains("email") || e.GetAttribute("name").Contains("email") ||
                 e.GetAttribute("type").Contains("user") || e.GetAttribute("name").Contains("user"));
         userEmailBox.SendKeys(Parameters[0]);
         passwordBox.SendKeys(Parameters[1]);
         driver.FindElementByTagName("form").Submit();
         return(true);
     }
     catch (Exception)
     {
         //Something went wrong
         return(false);
     }
 }
Пример #4
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("SoloLearn username password");
                Environment.Exit(1);
            }

            string userName = args[0];
            string passWord = args[1];

            Dictionary <string, int> countries = GetCountries();

            var driver = new PhantomJSDriver();

            driver.Navigate().GoToUrl(loginUrl);
            var userID = driver.FindElementById("Email");

            userID.Clear();
            userID.SendKeys(userName);
            var passID = driver.FindElementById("Password");

            passID.Clear();
            passID.SendKeys(passWord);

            var form = driver.FindElementByTagName("form");

            form.Submit();

            driver.Navigate().GoToUrl(scrapeUrl);

            int delay = 3000; // 3 seconds
            var javascriptInBrowser     = (IJavaScriptExecutor)driver;
            var detailsWrapper          = driver.FindElementsByClassName("detailsWrapper");
            var lastDetailsWrapperCount = detailsWrapper.Count;

            while (true)
            {
                javascriptInBrowser.ExecuteScript("arguments[0].scrollIntoView(true);",
                                                  detailsWrapper[lastDetailsWrapperCount - 1]);
                Thread.Sleep(delay);
                detailsWrapper = driver.FindElementsByClassName("detailsWrapper");
                if (detailsWrapper.Count == lastDetailsWrapperCount)
                {
                    break;
                }
                else
                {
                    lastDetailsWrapperCount = detailsWrapper.Count;
                    delay += 500; // add 1/2 a second to the delay
                }
            }
            string text = string.Empty;

            foreach (var detail in detailsWrapper)
            {
                text = detail.GetAttribute("innerText").ToUpperInvariant();
                foreach (KeyValuePair <string, int> kvp in countries)
                {
                    if (text.Contains(kvp.Key.ToUpperInvariant()))
                    {
                        countries[kvp.Key] += 1;
                        break; // don't look for multiple matches
                    }
                }
            }

            driver.Quit();
            driver.Dispose();

            var items = from pair in countries
                        orderby pair.Value descending
                        select pair;

            foreach (KeyValuePair <string, int> kvp in items)
            {
                Console.WriteLine("{0}\t{1}", kvp.Key, kvp.Value);
            }
        }