private BrowserApp(bool runHeadless)
        {
            try
            {
                if (runHeadless)
                {
                    var service = PhantomJSDriverService.CreateDefaultService();
                    service.HideCommandPromptWindow = true;
                    _browser = new PhantomJSDriver(service);
                }
                else
                {
                    var service = ChromeDriverService.CreateDefaultService();
                    service.HideCommandPromptWindow = true;
                    _browser = new ChromeDriver(service);
                }

                _browser.Navigate().GoToUrl(DevWebServer.RootUrl);

                // PhantomJS couldn't set cookies here, so use JS instead
                // https://github.com/detro/ghostdriver/issues/477#issuecomment-240915786
                var scriptExecutor = (IJavaScriptExecutor)_browser;
                scriptExecutor.ExecuteScript("document.cookie = 'cookie-notification-acknowledged=yes; path=/;'");
                scriptExecutor.ExecuteScript("document.cookie = 'Alpha2Entry=allow; path=/;'");
            }
            catch
            {
                Dispose();
                throw;
            }
        }
        /// <summary>
        /// REFERENCES:
        /// other approach:
        ///
        ///     http://stackoverflow.com/questions/18921099/add-proxy-to-phantomjsdriver-selenium-c
        ///         PhantomJSOptions phoptions = new PhantomJSOptions();
        ///         phoptions.AddAdditionalCapability(CapabilityType.Proxy, "http://localhost:9999");
        ///
        ///     driver = new PhantomJSDriver(phoptions);
        ///     - (24/04/2019) https://stackoverflow.com/a/52446115/3796898
        ///
        /// </summary>
        /// <param name="hostPgUrlPattern"></param>
        /// <param name="freeProxy"></param>
        /// <returns></returns>
        public static string LoadIPProxyDocumentContent(string hostPgUrlPattern, IPProxy freeProxy = null)
        {
            //var options = new ChromeOptions();
            //var userAgent = "user_agent_string";
            //options.AddArgument("--user-agent=" + userAgent);
            //IWebDriver driver = new ChromeDriver(options);

            var service = PhantomJSDriverService.CreateDefaultService(".\\");

            service.HideCommandPromptWindow = true;

            if (freeProxy != null)
            {
                service.ProxyType = freeProxy.Protocol == ProxyProtocolsEnum.HTTP ? "http" : "https:";
                var proxy = new Proxy
                {
                    HttpProxy = $"{freeProxy.IPAddress}:{freeProxy.PortNo}",
                };
                service.Proxy = proxy.HttpProxy;
            }

            var driver = new PhantomJSDriver(service)
            {
                Url = hostPgUrlPattern
            };

            driver.Navigate();
            var content = driver.PageSource;

            driver.Quit();

            return(content);
        }
Esempio n. 3
0
        private void Crawler_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;    //最大化窗体

            //加载cc域名对应的可用地址
            Action <string> setTbx1 = (s) => { textBox1.Text = s; };
            Action <string> setTbx2 = (s) => { textBox2.Text = s; };
            Action <string> setTbx3 = (s) => { textBox3.Text = s; };
            Action <bool>   setBtn1 = (s) => { button1.Enabled = s; };

            try
            {
                Task.Run(() =>
                {
                    var _service = PhantomJSDriverService.CreateDefaultService();
                    _service.HideCommandPromptWindow = true;
                    var driver = new PhantomJSDriver(_service);
                    driver.Navigate().GoToUrl("http://zc.97down.info");
                    var domain = driver.Url;
                    var zp     = domain + AppSettings.GetValue <string>("ListPageUrl_ZP");
                    var wm     = domain + AppSettings.GetValue <string>("ListPageUrl_WM");
                    var lc     = domain + AppSettings.GetValue <string>("ListPageUrl_LC");
                    textBox1.Invoke(setTbx1, zp);
                    textBox2.Invoke(setTbx2, wm);
                    textBox3.Invoke(setTbx3, lc);
                    button1.Invoke(setBtn1, true);
                });
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
Esempio n. 4
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="AdSenseSpawner" /> class.
        /// </summary>
        public AdSenseSpawner()
        {
            Cache = new List <IAdSenseDriver>();

            _driverService = PhantomJSDriverService.CreateDefaultService();
            _driverService.HideCommandPromptWindow = true;
        }
Esempio n. 5
0
        private static async Task ProductDetails(string url, int parentId)
        {
            var driverService = PhantomJSDriverService.CreateDefaultService();

            driverService.HideCommandPromptWindow = true;
            var driver = new PhantomJSDriver(driverService)
            {
                Url = url
            };

            driver.Navigate();
            var source = driver.PageSource;

            //var httpClient = new HttpClient(); // HtmlAgilityPack
            var htmlDocument = new HtmlDocument();

            //var html = await httpClient.GetStringAsync("https:" + url); // HtmlAgilityPack
            htmlDocument.LoadHtml(source);
            //var httpClient = new HttpClient(); // HtmlAgilityPack
            //var htmlDocument = new HtmlDocument(); // HtmlAgilityPack
            //var html = await httpClient.GetStringAsync(url); // HtmlAgilityPack
            //htmlDocument.LoadHtml(html); // HtmlAgilityPack
            var currentImage = htmlDocument.DocumentNode.Descendants("img").FirstOrDefault(node => node.GetAttributeValue("class", "").Equals("pdp-mod-common-image gallery-preview-panel__image"))?.ChildAttributes("src").FirstOrDefault()?.Value;
            var currentName  = htmlDocument.DocumentNode.Descendants("span").FirstOrDefault(node => node.GetAttributeValue("class", "").Equals("pdp-mod-product-badge-title"))?.InnerText.Trim();
            var currentPrice = htmlDocument.DocumentNode.Descendants("span").FirstOrDefault(node => node.GetAttributeValue("class", "").Contains("pdp-price"))?.InnerText.Trim();
            //var currentSale = htmlDocument.DocumentNode.Descendants("span").FirstOrDefault(node => node.GetAttributeValue("id", "").Equals("span-discount-percent"))?.InnerText.Trim();
            //var currentRegularPrice = htmlDocument.DocumentNode.Descendants("span").FirstOrDefault(node => node.GetAttributeValue("class", "").Equals("span-list-price"))?.InnerText.Trim();
            var currentSeller = htmlDocument.DocumentNode.Descendants("a").FirstOrDefault(node => node.GetAttributeValue("class", "").Contains("seller-name__detail-name"))?.InnerText.Trim();

            // Lưu DB
            //
            // End Lưu DB

            Console.WriteLine("Add ProductName: " + currentName);
        }
        public IWebDriver Create(string url)
        {
            lock (this)
            {
                var driverService = PhantomJSDriverService.CreateDefaultService();
                if (portCache.Contains(driverService.Port))
                {
                    driverService.Port = portCache.Max() + 1;
                }
                else
                {
                    portCache.Add(driverService.Port);
                }

                driverService.HideCommandPromptWindow = true;
                try
                {
                    var driver = new PhantomJSDriver(driverService);
                    driver.Manage().Timeouts().PageLoad = new TimeSpan((long)120E7);
                    driver.Navigate().GoToUrl(url);
                    return(driver);
                }
                catch (Exception exc)
                {
                    Console.WriteLine("err when navigate to : ");
                    Console.WriteLine(exc.Message);
                }
            }
            return(null);
        }
Esempio n. 7
0
        public RemoteWebDriver RegisterNewDriver(AccountViewModel account)
        {
            var options   = new PhantomJSOptions();
            var userAgent = new GetUserAgentQueryHandler(new DataBaseContext()).Handle(new GetUserAgentQuery
            {
                UserAgentId = account.UserAgentId
            });

            if (string.IsNullOrWhiteSpace(account.Proxy))
            {
                options.AddAdditionalCapability("phantomjs.page.settings.userAgent", userAgent);
                return(new PhantomJSDriver(options));
            }

            var service = PhantomJSDriverService.CreateDefaultService();

            service.AddArgument(string.Format("--proxy-auth={0}:{1}", account.ProxyLogin, account.ProxyPassword));
            service.AddArgument(string.Format("--proxy={0}", account.Proxy));

            options.AddAdditionalCapability("phantomjs.page.settings.userAgent", userAgent);

            var driver = new PhantomJSDriver(service, options);

            return(driver);
        }
Esempio n. 8
0
        public static Dictionary <string, double> ExecuteAndRead(string html, IEnumerable <string> elementNames)
        {
            var path = Path.Combine(Default.RangerFolder, fileName);

            // ToDo: Find a way to do this without writing to a file.
            File.WriteAllText(path, html);

            var service = PhantomJSDriverService.CreateDefaultService(Default.RangerFolder);

            service.HideCommandPromptWindow = true;

            var driver   = new PhantomJSDriver(service);
            var filePath = Path.Combine("file:///", path);
            var url      = new Uri(path);

            driver.Navigate().GoToUrl(url);

            var values = new Dictionary <string, double>();

            foreach (var elementName in elementNames)
            {
                var element = driver.FindElement(By.Id(elementName));
                var value   = double.Parse(element.Text);
                values.Add(elementName, value);
            }

            driver.Quit();
            File.Delete(path);

            return(values);
        }
Esempio n. 9
0
        private static void SelectBrowser(string browser)
        {
            switch (browser)
            {
            case "Firefox":
                _driver = new FirefoxDriver();
                break;

            case "Chrome":
                var chromeDriverService = ChromeDriverService.CreateDefaultService(DriversPath, "chromedriver.exe");
                chromeDriverService.Start();
                _driver        = new RemoteWebDriver(chromeDriverService.ServiceUrl, DesiredCapabilities.Chrome());
                _driverService = chromeDriverService;
                break;

            case "IE":
                _driver = new InternetExplorerDriver(DriversPath);
                break;

            case "PhantomJS":
                var phantomJsPath          = SmokeTestPaths.GetPhantomJsPath();
                var phantomJsDriverService = PhantomJSDriverService.CreateDefaultService(phantomJsPath);
                _driver        = new PhantomJSDriver(phantomJsDriverService);
                _driverService = phantomJsDriverService;
                break;

            default:
                throw new ArgumentException("Unknown browser");
            }
        }
Esempio n. 10
0
        private void createMapTileScreenshots(string nodeId, string latitude, string longitude)
        {
            String pathScreenshots = System.IO.Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory) + Path.DirectorySeparatorChar + "screenshots" + Path.DirectorySeparatorChar;

            Console.WriteLine("Screenshots Path: " + pathScreenshots);
            try
            {
                // setting for proxy
                //PhantomJSOptions phOptions = new PhantomJSOptions();
                //phOptions.AddAdditionalCapability(CapabilityType.Proxy, "cache.itb.ac.id");

                // hide cmd windows of phantomsjs
                var driverService = PhantomJSDriverService.CreateDefaultService();
                driverService.HideCommandPromptWindow = true;

                // initiate phantomjs driver
                PhantomJSDriver phantom;
                phantom = new PhantomJSDriver(driverService);
                // setting the default timeout to 30 seconds
                phantom.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30));
                string screenshotUrl = "http://localhost/bsts_routing/tilegen/v2/index.php?latitude=" + latitude + "&longitude=" + longitude;
                phantom.Navigate().GoToUrl(screenshotUrl);

                // grab the snapshot
                Screenshot sh        = phantom.GetScreenshot();
                TimeUtils  timeUtils = new TimeUtils();
                string     fileName  = nodeId + "_" + Convert.ToString(timeUtils.ToUnixTime(DateTime.Now)) + ".png";
                sh.SaveAsFile(pathScreenshots + fileName, ImageFormat.Png);
                phantom.Quit();
            }
            catch (Exception error)
            {
                Console.WriteLine(error.Message);
            }
        }
Esempio n. 11
0
        static void TestPhantom()
        {
            var driverService = PhantomJSDriverService.CreateDefaultService();

            driverService.HideCommandPromptWindow = true;

            var driver = new PhantomJSDriver(driverService);

            driver.Url = "https://www.kak-noviy.ru/sell/phones/apple/iphone-5/64gb-white";
            driver.Manage().Window.Size = new System.Drawing.Size(1920, 1080);
            driver.Navigate();

            var source = driver.PageSource;
            var label1 = driver.FindElementByXPath("//label[text()='Как новый']");
            var label2 = driver.FindElementByXPath("//label[text()='Устройство полностью исправно']");
            var label3 = driver.FindElementByXPath("//label[text()='Полная комплектация']");
            var label4 = driver.FindElementByXPath("//label[text()='Блокировки отсутствуют']");

            label1.Click();
            label2.Click();
            label3.Click();
            label4.Click();
            WaitForAjax(driver);
            driver.GetScreenshot().SaveAsFile("test.png", System.Drawing.Imaging.ImageFormat.Png);
            var price = driver.FindElementByClassName("price");

            Console.WriteLine(price.Text);
            driver.Close();
            driver.Quit();
        }
Esempio n. 12
0
        void pullData(string inputURL, string sportName)
        {
            Console.WriteLine("Starting Pull of " + inputURL);
            PhantomJSDriverService service = PhantomJSDriverService.CreateDefaultService("..\\..\\packages\\PhantomJS.2.1.1\\tools\\phantomjs");

            service.IgnoreSslErrors = true;
            service.SslProtocol     = "any";
            PhantomJSDriver driver = new PhantomJSDriver(service);

            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));

            string source = "";

            try
            {
                driver.Navigate().GoToUrl(inputURL);
                driver.FindElementByClassName("timezone");

                source = driver.PageSource;
            }
            catch (Exception e)
            {
                Helper.writeError(e.ToString(), (fileName + sportName));
            }

            Helper.writePulledData(source, (fileName + sportName));
            driver.Quit();

            Console.WriteLine("Data pulled");
        }
Esempio n. 13
0
        public PhantomJSDriverHelper(string cookies, string domain)
        {
            var _option = new PhantomJSOptions();

            _option.AddAdditionalCapability(@"phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36");

            var _service = PhantomJSDriverService.CreateDefaultService();

            //代理
            _service.ProxyType = "none"; //'http', 'socks5' or 'none'
            _service.Proxy     = "";     //{address}:{port}
            //不加载图片
            _service.LoadImages = false;
            //忽略SSL证书错误
            _service.IgnoreSslErrors = true;
            //隐藏命令提示窗口
            _service.HideCommandPromptWindow = true;
            //日志文件路径
            _service.LogFile = "";
            //Cookie文件路径
            //_service.CookiesFile = "PhantomJSCookie.json";
            //_service.DiskCache = true;
            //_service.MaxDiskCacheSize = 10240;
            //_service.LocalStoragePath = "LocalStoragePath";
            _webDriver = new PhantomJSDriver(_service, _option);


            if (!string.IsNullOrEmpty(cookies))
            {
                AddCookie(cookies, domain);
            }
        }
Esempio n. 14
0
        public IWebDriver createDriver(ICapabilities capabilities)
        {
            /**
             * Transform capabilities to Dictionary<string,object> and place it
             * reflectively as member of ChromeOptions.
             *
             * Sucks, but everything here is immutable, non enumerable, etc
             */
            DesiredCapabilities dc = (DesiredCapabilities)capabilities;

            FieldInfo[] fields = dc.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
            Dictionary <string, object> values = (Dictionary <string, object>)fields[0].GetValue(dc);

            PhantomJSOptions options = new PhantomJSOptions();

            foreach (KeyValuePair <string, object> capability in values)
            {
                options.AddAdditionalCapability(capability.Key.ToString(), (capability.Value == null ? "" : capability.Value.ToString()));
            }

            string executable = AppDomain.CurrentDomain.BaseDirectory + @"\libs";
            PhantomJSDriverService service = PhantomJSDriverService.CreateDefaultService(executable);
            IWebDriver             driver  = (IWebDriver) new PhantomJSDriver(service, options);

            return(driver);
        }
Esempio n. 15
0
        public IpModuleManager(IpModule module)
        {
            string[] phantomArgs = new string[] { "--webdriver-loglevel=NONE" };

            PhantomJSOptions options = new PhantomJSOptions();

            options.AddAdditionalCapability("phantomjs.cli.args", phantomArgs);

            Module = module;
            var driverService = PhantomJSDriverService.CreateDefaultService();

            driverService.HideCommandPromptWindow = true;
            driverService.LogFile = "phantomJSService.log";

            driver = new PhantomJSDriver(driverService, options);
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));


            loginUrl      = string.Format("{0}/login_page.html", Module.Url.Value.ToString());
            logoutUrl     = string.Format("{0}/logout.html", Module.Url.Value.ToString());
            versionUrl    = string.Format("{0}/version.html", Module.Url.Value.ToString());
            eventUrl      = string.Format("{0}/event.html", Module.Url.Value.ToString());
            statusLiveUrl = string.Format("{0}/statuslive.html", Module.Url.Value.ToString());

            Devices = new List <Device>();
        }
Esempio n. 16
0
        public List <Song> GetSearch()
        {
            List <Song> search_results = new List <Song>();
            IReadOnlyCollection <IWebElement> search_content;
            List <string> search_content_ids = new List <string>();

            var service = PhantomJSDriverService.CreateDefaultService();

            service.HideCommandPromptWindow = true;
            IWebDriver driver = new PhantomJSDriver(service);

            driver.Url = "http://www.playzer.fr";

            IJavaScriptExecutor js = (IJavaScriptExecutor)driver;


            js.ExecuteScript("arguments[0].click();", driver.FindElement(By.XPath("//*[@id='panel_search']/img")));
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
            Thread.Sleep(TimeSpan.FromSeconds(1));
            IWebElement search = driver.FindElement(By.Id("search_engine"));

            search.SendKeys(searchBox.Text);
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
            Thread.Sleep(TimeSpan.FromSeconds(2));
            js.ExecuteScript("arguments[0].click();", driver.FindElement(By.XPath("//*[@id='search_clips_tab']")));
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
            // Thread.Sleep(TimeSpan.FromSeconds(2));
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
            IWebElement result = driver.FindElement(By.Id("search_results"));

            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
            //  Thread.Sleep(TimeSpan.FromSeconds(2));
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
            search_content = result.FindElements(By.XPath("//div[@class='content transition search_item_content']"));
            //   Thread.Sleep(TimeSpan.FromSeconds(2));
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));

            int i = 1;

            foreach (IWebElement ids in search_content)
            {
                string song_ID = ids.GetAttribute("id");

                string title = driver.FindElement(By.XPath("//*[@id='" + song_ID + "']/div[2]")).Text;

                string artist = driver.FindElement(By.XPath("//*[@id='" + song_ID + "']/div[3]")).Text;

                string url = driver.FindElement(By.XPath("//*[@id='" + song_ID + "']/div[1]/img[2]")).GetAttribute("src");

                search_results.Add(new Song(title, artist, song_ID,
                                            url, i));
                i++;
            }

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

            return(search_results);
        }
        public Locate()
        {
            var service = PhantomJSDriverService.CreateDefaultService(Environment.CurrentDirectory);

            service.WebSecurity             = false;
            service.HideCommandPromptWindow = true;
            driver = new PhantomJSDriver(service);
            driver.Manage().Window.Size = new System.Drawing.Size(1240, 1240);

            //var chromeOptions = new ChromeOptions();
            //chromeOptions.AddArguments("headless");
            //var chromeDriverService = ChromeDriverService.CreateDefaultService();
            //// chromeDriverService.HideCommandPromptWindow = true;
            //driver = new ChromeDriver(chromeDriverService,chromeOptions);

            //driver.Navigate().GoToUrl("https://facebook.com");
            //Thread.Sleep(3000);
            //Console.WriteLine(driver.WindowHandles.Count);
            //driver.ExecuteScript("window.open('https://google.com','_blank');");
            //Thread.Sleep(3000);
            //Console.WriteLine(driver.WindowHandles.Count);

            Console.WriteLine(driver.Capabilities.ToString());
            SignInUrl    = "https://www.clarkcountycourts.us/Portal/Account/Login";
            SignInUrl1   = "https://odysseyadfs.tylertech.com/IdentityServer/account/signin?ReturnUrl=%2fIdentityServer%2fissue%2fwsfed%3fwa%3dwsignin1.0%26wtrealm%3dhttps%253a%252f%252fOdysseyADFS.tylertech.com%252fadfs%252fservices%252ftrust%26wctx%3d4d2b3478-8513-48ad-8998-2652d72a38e9%26wauth%3durn%253a46%26wct%3d2018-04-29T15%253a42%253a35Z%26whr%3dhttps%253a%252f%252fodysseyadfs.tylertech.com%252fidentityserver&wa=wsignin1.0&wtrealm=https%3a%2f%2fOdysseyADFS.tylertech.com%2fadfs%2fservices%2ftrust&wctx=4d2b3478-8513-48ad-8998-2652d72a38e9&wauth=urn%3a46&wct=2018-04-29T15%3a42%3a35Z&whr=https%3a%2f%2fodysseyadfs.tylertech.com%2fidentityserver";
            HomePageUrl  = "https://www.clarkcountycourts.us/Portal/";
            case_ref_num = new CrossRefNumber();
        }
        // Prepares a PhantomJS driver that does not dislay its logs in the console window.
        // The trade-off is, you have to give it a file path to output to instead.
        static IWebDriver CreateInfolessPhantom(string logFilePath)
        {
            PhantomJSDriverService service = PhantomJSDriverService.CreateDefaultService();

            service.LogFile = logFilePath;
            return(new PhantomJSDriver(service));
        }
Esempio n. 19
0
 public static void GenerateDriver(int driverKind)
 {
     try
     {
         if (WebDriver == null)
         {
             if (driverKind == 0) // PhantomJS
             {
                 PhantomJSDriverService service = PhantomJSDriverService.CreateDefaultService();
                 service.IgnoreSslErrors = true;
                 service.LoadImages      = false;
                 service.ProxyType       = "none";
                 WebDriver = new PhantomJSDriver(service);
             }
             else if (driverKind == 1) //Chrome
             {
                 var chromeDriverService = ChromeDriverService.CreateDefaultService();
                 chromeDriverService.HideCommandPromptWindow = true;
                 WebDriver = new ChromeDriver(chromeDriverService, new ChromeOptions());
                 Console.WriteLine("###      Driver generated.");
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Esempio n. 20
0
        int look()
        {
            var driverService = PhantomJSDriverService.CreateDefaultService(Environment.CurrentDirectory);

            driverService.HideCommandPromptWindow = true;
            IWebDriver driver = new PhantomJSDriver(driverService);

            driver.Navigate().GoToUrl("https://www.truecaller.com/");
            try
            {
                if (driver.PageSource.Contains("Sign out"))
                {
                    return(1);
                }
                else if (driver.PageSource.Contains("Sign in"))
                {
                    return(0);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Can't find_out");
                MessageBox.Show(e.Message);
            }
            finally
            {
                driver.Close();
                driver.Quit();
            }
            return(3);
        }
Esempio n. 21
0
        /// <summary>
        /// 创同步建爬虫
        /// </summary>
        /// <param name="uri">爬虫URL地址</param>
        /// <param name="proxy">代理服务器</param>
        /// <returns>网页源代码</returns>
        public PhantomJSDriver StartSync(Uri uri, Script script, Operation operation)
        {
            try
            {
                var _service = PhantomJSDriverService.CreateDefaultService();
                var _option  = new PhantomJSOptions();
                var driver   = new PhantomJSDriver(_service, _option);

                var watch = DateTime.Now;
                driver.Navigate().GoToUrl(uri.ToString());
                if (script != null)
                {
                    ExecuteScript(script, driver);
                }
                if (operation != null)
                {
                    ExecuteAction(operation, driver);
                }

                var threadId     = System.Threading.Thread.CurrentThread.ManagedThreadId;
                var milliseconds = DateTime.Now.Subtract(watch).Milliseconds;
                //var pageSource = driver.PageSource;
                return(driver);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 22
0
        void sign_out()
        {
            var driverService = PhantomJSDriverService.CreateDefaultService(Environment.CurrentDirectory);

            driverService.HideCommandPromptWindow = true;
            IWebDriver driver = new PhantomJSDriver(driverService);

            driver.Navigate().GoToUrl("https://www.truecaller.com/");
            try
            {
                var    div = driver.FindElement(By.TagName("div")).FindElement(By.XPath("//*[contains(text(), 'Sign out')]"));
                string js  = "arguments[0].click();";

                ((IJavaScriptExecutor)driver).ExecuteScript(js, div);

                Thread.Sleep(10);


                MessageBox.Show("Signed Out Successfully");
                lbl_Check.Text       = "Signed Out";
                btn_Sign_IN.Enabled  = true;
                btn_Sign_OUT.Enabled = false;
            }
            catch (Exception e)
            {
                MessageBox.Show("You Need to Signed in, In order to get Signed Out");
                MessageBox.Show(e.Message);
            }
            finally
            {
                driver.Close();
                driver.Quit();
            }
        }
Esempio n. 23
0
 public PhantomRunner()
 {
     driverService            = PhantomJSDriverService.CreateDefaultService(AppDomain.CurrentDomain.BaseDirectory);
     driverService.LoadImages = false;
     driverService.ProxyType  = "http";
     driverService.Proxy      = "81.169.141.196:80";
 }
Esempio n. 24
0
        private void GetChapterComicPage()
        {
            var service = PhantomJSDriverService.CreateDefaultService();

            service.DiskCache               = true;
            service.IgnoreSslErrors         = true;
            service.HideCommandPromptWindow = true;
            service.LoadImages              = false;
            service.ProxyType               = "none";
            service.LocalToRemoteUrlAccess  = true;
            PhantomJSDriver driver = new PhantomJSDriver(service, new PhantomJSOptions(), TimeSpan.FromSeconds(120));

            driver.Navigate().GoToUrl(Url);

            var element = driver.FindElementById("page_select");

            foreach (var pages in driver.FindElements(By.XPath("//*[@id=\"page_select\"]/option")))
            {
                var page = new ComicPage();
                page.PageImgUrl = "https:" + pages.GetAttribute("value");
                page.PageNo     = pages.Text.GetNumber();
                _comicPageList.Add(page);
            }
            driver.Close();
            driver.Dispose();
        }
Esempio n. 25
0
        /// <summary>
        /// Start PhantomJS on aiondatabase website.
        /// </summary>
        public static void PhantomStart()
        {
            try
            {
                DriverService = PhantomJSDriverService.CreateDefaultService();
                DriverService.HideCommandPromptWindow = true;
                Driver     = new PhantomJSDriver(DriverService);
                Driver.Url = "http://aiondatabase.net/en/";
                Driver.Navigate();
            }
            catch (Exception e)
            {
                switch (e.Message)
                {
                case "The path is not of a legal form.":
                    Console.WriteLine("\nMissing WebDriver.dll\n");
                    Console.ReadKey();
                    Environment.Exit(-1);
                    break;

                default:
                    Main();
                    break;
                }
            }
        }
Esempio n. 26
0
        static public void getItems(ref TimeStamp cTimestep)
        {
            var service = PhantomJSDriverService.CreateDefaultService();
            var phantomJSDriverService = PhantomJSDriverService.CreateDefaultService(@"C:\phantomjs-2.1.1-windows\bin");

            using (PhantomJSDriver driver = new PhantomJSDriver(phantomJSDriverService))
            {
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
                driver.Url = @"http://www.finanzen.net/anleihen/" + cTimestep.link;
                driver.Navigate();
                //Console.WriteLine(driver.PageSource);
                try
                {
                    IWebElement element = driver.FindElement(By.ClassName("col-xs-5"));
                    cTimestep.lastprice = Convert.ToDouble(element.Text.Replace(",", ".").Replace("-", "0").Replace("%", null).Replace("±", null));
                    element             = driver.FindElement(By.ClassName("col-xs-4"));
                    cTimestep.change    = Convert.ToDouble(element.Text.Replace(",", String.Empty).Replace("-", "0").Replace("+", null).Replace("±", null));
                    element             = driver.FindElement(By.ClassName("col-xs-3"));
                    cTimestep.pctChange = Convert.ToDouble(element.Text.Replace(",", ".").Replace("-", "0").Replace("%", null).Replace("+", null).Replace("±", null));
                    cTimestep.high      = cTimestep.lastprice;
                    cTimestep.low       = cTimestep.lastprice;
                    cTimestep.timestamp = DateTime.Now;
                }
                catch (Exception e)
                {
                    throw new Exception("Problem getting the input" + e + " \n WITH" + cTimestep.id);
                }
            }
        }
Esempio n. 27
0
        void pullData(string inputURL, string sportName)
        {
            Console.WriteLine("Starting Pull of " + inputURL);
            PhantomJSDriverService service = PhantomJSDriverService.CreateDefaultService("..\\..\\packages\\PhantomJS.2.1.1\\tools\\phantomjs");

            service.IgnoreSslErrors        = true;
            service.SslProtocol            = "any";
            service.LocalToRemoteUrlAccess = true;
            //service.AddArgument("--ignore-ssl-errors=true");
            // service.AddArgument("--ssl-protocol=tlsv1");
            //service.GhostDriverPath = "E:\\SportsBetting\\packages\\PhantomJS.2.1.1\\tools\\phantomjs";
            //PhantomJSDriver driver = new PhantomJSDriver("E:\\SportsBetting\\packages\\PhantomJS.2.1.1\\tools\\phantomjs");
            PhantomJSDriver driver = new PhantomJSDriver(service);

            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));
            //driver.Url = inputURL;

            string source = "";

            try
            {
                driver.Navigate().GoToUrl(inputURL);
                source = driver.PageSource;
            }
            catch (Exception e)
            {
                Helper.writeError(e.ToString(), (fileName + sportName));
            }

            Helper.writePulledData(source, (fileName + sportName));
            driver.Quit();

            Console.WriteLine("Data pulled");
        }
Esempio n. 28
0
        /// <summary>
        /// Creates the web driver from the specified browser factory configuration.
        /// </summary>
        /// <returns>The configured web driver.</returns>
        protected override IWebDriver CreateLocalDriver()
        {
            var phantomJsDriverService = PhantomJSDriverService.CreateDefaultService();

            phantomJsDriverService.HideCommandPromptWindow = true;
            return(new PhantomJSDriver(phantomJsDriverService));
        }
Esempio n. 29
0
        private void MyTestInitialize()
        {
            baseurl = ConfigurationManager.AppSettings["baseurl"].ToString();
            if (ConfigurationManager.AppSettings["usePhantom"].ToString() == "true")
            {
                if (ConfigurationManager.AppSettings["useDocker"].ToString() == "true")
                {
                    this.Driver = new RemoteWebDriver(new Uri(ConfigurationManager.AppSettings["webDriverURL"].ToString()), DesiredCapabilities.Chrome());
                    baseurl     = ConfigurationManager.AppSettings["baseurlDocker"].ToString();
                }
                else
                {
                    this.Driver = new PhantomJSDriver();
                    var driverService = PhantomJSDriverService.CreateDefaultService();
                    driverService.HideCommandPromptWindow = true;

                    this.Driver = new PhantomJSDriver(driverService);
                }
            }
            else
            {
                this.Driver = new ChromeDriver();
            }

            this.Wait = new WebDriverWait(this.Driver, TimeSpan.FromSeconds(30));
        }
Esempio n. 30
0
        public bool ConnectionTest(string login, string password)
        {
            var service = PhantomJSDriverService.CreateDefaultService();

            service.IgnoreSslErrors = true;
            service.LoadImages      = false;
            service.ProxyType       = "none";
            service.SslProtocol     = "any";

            var options = new PhantomJSOptions();

            options.AddAdditionalCapability("phantomjs.page.settings.userAgent", _phantomJsUserAgent);

            var phantomCheckConnection = new PhantomJSDriver(service, options);

            phantomCheckConnection.Navigate().GoToUrl($"{BaseUrl}/accounts/login");

            phantomCheckConnection.FindElement(By.Id("input_login_email")).SendKeys(login);
            phantomCheckConnection.FindElement(By.Id("input_login_password")).SendKeys(password);
            phantomCheckConnection.FindElement(By.Id("signin_submit")).Click();

            Func <IWebDriver, bool> del = ExpectedConditions.UrlContains($"{BaseUrl}/app/");
            var result = del.Invoke(phantomCheckConnection);

            phantomCheckConnection.Quit();
            return(result);
        }