コード例 #1
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().SetPageLoadTimeout(TimeSpan.FromSeconds(10));
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));
            //driver.Url = inputURL;

            string source = "";

            try
            {
                driver.Navigate().GoToUrl(inputURL);

                if (targetLink != "")
                {
                    //Console.WriteLine("here");

                    //var firstNext = driver.FindElementByCssSelector(dropDownLink);
                    //firstNext.Click();
                    //Thread.Sleep(5000);

                    var next = driver.FindElementById(targetLink);

                    next.Click();

                    Thread.Sleep(10000);
                }

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

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

            Console.WriteLine("Data pulled");
        }
コード例 #2
0
ファイル: Hooks.cs プロジェクト: feldrim/SecurityEssentials
        public static void BeforeFeature()
        {
            var        webBrowserProxy = ConfigurationManager.AppSettings["WebBrowserProxy"];
            var        webBrowserType  = ConfigurationManager.AppSettings["WebBrowserType"];
            IWebDriver webDriver;

            if (!string.IsNullOrEmpty(webBrowserProxy))
            {
                var profile = new FirefoxProfile();
                var proxy   = new Proxy
                {
                    HttpProxy = webBrowserProxy,
                    FtpProxy  = webBrowserProxy,
                    SslProxy  = webBrowserProxy
                };
                profile.SetProxyPreferences(proxy);
                webDriver = new FirefoxDriver(profile);
            }
            else
            {
                switch (webBrowserType)
                {
                case "Chrome":
                    webDriver = new ChromeDriver();
                    break;

                case "FireFox":
                    webDriver = new FirefoxDriver();
                    break;

                case "IE":
                case "Internet Explorer":
                    webDriver = new InternetExplorerDriver();
                    break;

                case "PhantomJS":
                    webDriver = new PhantomJSDriver();
                    break;

                default:
                    throw new Exception($"Unable to set browser type {webBrowserType}");
                }
            }

            webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
            FeatureContext.Current.SetWebDriver(webDriver);

            var baseUri = new Uri(ConfigurationManager.AppSettings["WebServerUrl"]);

            FeatureContext.Current.SetBaseUri(baseUri);
        }
コード例 #3
0
        public IWebDriver Create()
        {
            IWebDriver driver;
            var        driverToUse           = ConfigurationHelper.Get <DriverToUse>("DriverToUse");
            var        browserStackIndicator = ConfigurationHelper.Get <bool>("UseBrowserStack");
            var        url = ConfigurationHelper.Get <String>("TargetUrl");

            if (browserStackIndicator)
            {
                driver = CreateGridDriver(driverToUse);
            }
            else
            {
                switch (driverToUse)
                {
                case DriverToUse.InternetExplorer:
                    driver = new InternetExplorerDriver();
                    break;

                case DriverToUse.Firefox:

                    driver = new FirefoxDriver();
                    break;

                case DriverToUse.Chrome:
                    driver = new ChromeDriver();
                    break;

                case DriverToUse.Safari:
                    driver = new SafariDriver();
                    break;

                case DriverToUse.Phantomjs:
                    driver = new PhantomJSDriver();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            driver.Manage().Window.Maximize();
            var timeouts = driver.Manage().Timeouts();


            driver.Manage().Window.Maximize();
            driver.Navigate().GoToUrl(url);

            return(driver);
        }
コード例 #4
0
ファイル: Driver.cs プロジェクト: uyogesh/OddsScrape
 public Driver()
 {
     writer  = new DbWriter();
     service = PhantomJSDriverService.CreateDefaultService();
     service.HideCommandPromptWindow = true;
     opt = new PhantomJSOptions();
     opt.AddAdditionalCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome / 40.0.2214.94 Safari / 537.36");
     opt.AddAdditionalCapability("IsJavaScriptEnabled", true);
     //opt.AddAdditionalCapability("IsApplicationCacheEnabled", true);
     driver = new PhantomJSDriver(service, opt);
     exec   = (IJavaScriptExecutor)driver;
     driver.Navigate().GoToUrl("http://www.oddsportal.com");
     login();
 }
コード例 #5
0
        /// <summary>
        /// 高级爬虫
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="script"></param>
        /// <param name="operation"></param>
        /// <returns></returns>
        public async Task Start(Uri uri, Script script, Operation operation, bool Closed = true)
        {
            await Task.Run(() => {
                if (OnStrart != null)
                {
                    this.OnStrart(this, new OnStartEventArgs(uri));
                }
                Driver = new PhantomJSDriver(_service, _options);

                try{
                    Driver.Navigate().GoToUrl(uri);
                    var watch = DateTime.Now;
                    if (script != null)
                    {
                        Driver.ExecuteScript(script.Code, script.Args);
                    }
                    if (operation.Action != null)
                    {
                        operation.Action.Invoke(Driver);
                    }
                    var driverWait = new WebDriverWait(Driver, TimeSpan.FromMilliseconds(operation.TimeOut));
                    if (operation.Condition != null)
                    {
                        driverWait.Until(operation.Condition);
                    }
                    var ThreadId     = Thread.CurrentThread.ManagedThreadId;
                    var milliseconds = DateTime.Now.Subtract(watch).Milliseconds;
                    var pageSoure    = Driver.PageSource;
                    if (this.OnCompleted != null)
                    {
                        this.OnCompleted(this, new OnCompletedEventArgs(uri, ThreadId, milliseconds, pageSoure, Driver));
                    }
                }
                catch (Exception ex)
                {
                    if (this.OnError != null)
                    {
                        this.OnError(this, new OnErrorEventArgs(uri, ex));
                    }
                }
                finally
                {
                    if (Closed)
                    {
                        Driver.Close();
                        Driver.Quit();
                    }
                }
            });
        }
コード例 #6
0
        private void ChooseDriverInstance(BrowserType browserType)
        {
            if (browserType == BrowserType.Chrome)
            {
                int lrg = 1920; // Longeur ICI
                int lng = 1080; // Largeur ICI

                int lngForScreenShot = lng + (Int32)127;
                int lrgForScreenShot = lrg + 37;

                ChromeOptions options = new ChromeOptions();
                //options.AddArgument("--headless");
                options.AddArgument("--window-size=" + lrg + "," + lngForScreenShot);
                //options.EnableMobileEmulation("iPhone 6 Plus");
                _driver = new ChromeDriver(@"C:/WEBDRIVER", options);
                _driver.Manage().Window.Maximize();
            }
            else if (browserType == BrowserType.Firefox)
            {
                FirefoxBinary  binary         = new FirefoxBinary(@"C:/Program Files/Mozilla Firefox/firefox.exe");
                FirefoxProfile firefoxProfile = new FirefoxProfile();
                //FirefoxDriverService service = FirefoxDriverService.CreateDefaultService();
                //service.FirefoxBinaryPath = @"C:\\Program Files\\Mozilla Firefox";
                //service.HideCommandPromptWindow = true;
                //service.SuppressInitialDiagnosticInformation = true;
                //_driver = new FirefoxDriver();
                _driver = new FirefoxDriver(binary, firefoxProfile);
                _driver.Manage().Window.Maximize();
            }
            else if (browserType == BrowserType.IE)
            {
                _driver = new InternetExplorerDriver(@"C:/WEBDRIVER");
                _driver.Manage().Window.Maximize();
            }
            else if (browserType == BrowserType.Edge)
            {
                _driver = new EdgeDriver(@"C:/WEBDRIVER");
                _driver.Manage().Window.Maximize();
            }
            else if (browserType == BrowserType.Opera)
            {
                _driver = new OperaDriver("C:/WEBDRIVER");
                _driver.Manage().Window.Maximize();
            }
            else if (browserType == BrowserType.HeadLess)
            {
                _driver = new PhantomJSDriver("C:/WEBDRIVER");
                _driver.Manage().Window.Maximize();
            }
        }
コード例 #7
0
        public void DevicesAreShownInTheTable()
        {
            var driver = new PhantomJSDriver {
                Url = "http://localhost:51790/Device"
            };

            driver.Navigate();

            Thread.Sleep(1000);

            var po = new DevicePageObject(driver);

            Assert.AreNotEqual(0, po.GetDevicesCount());
        }
コード例 #8
0
 /// <summary/>
 protected virtual void Dispose(bool fDisposing)
 {
     System.Diagnostics.Debug.WriteLineIf(!fDisposing, "****** Missing Dispose() call for " + GetType() + ". *******");
     if (fDisposing && !IsDisposed)
     {
         // dispose managed and unmanaged objects
         if (_driver != null)
         {
             _driver.Dispose();
         }
         _driver = null;
     }
     IsDisposed = true;
 }
コード例 #9
0
        private static List <PropertySchool> GetSchools(PhantomJSDriver driver, long ID)
        {
            try
            {
                string Type = String.Empty;                                                        //у нас три типа школ, по умолчанию открывается начальная
                List <PropertySchool> schools = new List <PropertySchool>();
                driver.ExecuteScript("document.querySelector('#schoolsCard .clickable').click()"); //открываем список школ, чтобы он прогрузился
                System.Threading.Thread.Sleep(1000);

                for (int i = 0; i < 3; i++)
                {
                    driver.ExecuteScript(String.Format("document.querySelectorAll('div.mbl.schoolListContainer > div > ul > li > div')[{0}].click()", i)); //нажимаем на кнопку с нуным списком школ
                    switch (i)
                    {
                    case 0:
                        Type = Constants.SchoolType.Elementary;
                        break;

                    case 1:
                        Type = Constants.SchoolType.Middle;
                        break;

                    case 2:
                        Type = Constants.SchoolType.HighSchool;
                        break;
                    }
                    System.Threading.Thread.Sleep(1000);
                    var schoolsList = driver.FindElementsByCssSelector(".line.pls.bbs.pvm"); //выбираем список
                    foreach (var school in schoolsList)
                    {
                        PropertySchool temp = new PropertySchool();
                        temp.homeID     = ID;
                        temp.Type       = Type;
                        temp.SchoolName = school.FindElement(By.CssSelector("a")).Text;
                        temp.Grades     = school.FindElement(By.CssSelector(".line > div")).Text.Replace("Grades: ", String.Empty);
                        temp.Distance   = Convert.ToDouble(school.FindElement(By.CssSelector(".line > div:nth-child(2)")).Text.Replace(" mi", String.Empty));
                        temp.Address    = school.FindElement(By.CssSelector(".typeLowlight")).Text;
                        temp.Rank       = school.FindElement(By.CssSelector(".txtC")).Text;
                    }
                }
                return(schools);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Не удалось получить список школ: {},   {}", ex.Message, ex.StackTrace);
                return(null);

                throw;
            }
        }
コード例 #10
0
 public string CreateStaticContent(string websiteKey, string url)
 {
     using (var driver = new PhantomJSDriver())
     {
         SetupBrowserWindow(driver);
         string content;
         driver.Navigate().GoToUrl(url);
         content = driver.PageSource;
         _dataService.Save(websiteKey, url, content);
         Common common = new Common();
         driver.GetScreenshot().SaveAsFile("c:\\Temp\\" + websiteKey + "\\" + common.GetFileName(url) + ".png", System.Drawing.Imaging.ImageFormat.Png);
         return(content);
     }
 }
コード例 #11
0
        private string GetBrowserVersion(string browser)
        {
            var             directoryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Drivers");
            RemoteWebDriver driver;

            switch (browser)
            {
            case "chrome":
                driver = new ChromeDriver(directoryPath);
                break;

            case "firefox":
                FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(directoryPath, "geckodriver.exe");
                service.Port = 64444;

                var options = new FirefoxOptions();
                options.SetPreference("browser.private.browsing.autostart", true);
                driver = new FirefoxDriver(service, options, TimeSpan.FromSeconds(30));
                break;

            case "ie":
                driver = new InternetExplorerDriver(directoryPath);
                break;

            case "edge":
                driver = new EdgeDriver(directoryPath);
                break;

            case "opera":
                driver = new OperaDriver(directoryPath);
                break;

            case "safari":
                driver = new SafariDriver(directoryPath);
                break;

            case "phantomjs":
                driver = new PhantomJSDriver(directoryPath);
                break;

            default:
                driver = new ChromeDriver(directoryPath);
                break;
            }

            var capability = driver.Capabilities;

            driver.Quit();
            return(capability.Version);
        }
コード例 #12
0
        protected override object StartDriver(int pageLoadTimeout = 60, int scriptTimeout = 60, bool isMaximize = false)
        {
            PhantomJSOptions op = (PhantomJSOptions)Drivers.DriverOptions;

            if (op == null)
            {
                op = new PhantomJSOptions();
            }
            PhantomJSDriver driver = new PhantomJSDriver(Drivers.PhantomJSDriverService, op);

            driver.Manage().Timeouts().SetPageLoadTimeout(System.TimeSpan.FromSeconds(pageLoadTimeout));
            driver.Manage().Timeouts().SetScriptTimeout(System.TimeSpan.FromSeconds(scriptTimeout));
            return(driver);
        }
コード例 #13
0
        /// <summary>
        /// Initializes the Selenium webdriver and logs into the CHORDS portal
        /// </summary>
        /// <param name="portalUrl"></param>
        public static void Initialize(string portalUrl)
        {
            PortalUrl = portalUrl;

            Driver = new PhantomJSDriver();
            //Driver = new ChromeDriver();

            Client = new HttpClient()
            {
                Timeout = TimeSpan.FromMilliseconds(Config.DefaultTimeout)
            };

            Login();
        }
コード例 #14
0
ファイル: ComparisonTests.cs プロジェクト: veersamrat/Optimus
        public IWebElement PhFind(PhantomJSDriver browser, IWebElement parent, By by)
        {
            var _wait = new WebDriverWait(browser, TimeSpan.FromSeconds(120));

            try
            {
                var result = _wait.Until(x => parent.FindElements(by).FirstOrDefault() != null);
            }
            catch
            {
            }

            return(parent.FindElement(by));
        }
コード例 #15
0
ファイル: BasePage.cs プロジェクト: tspascoal/MercuryHealth
        //public static HomePage Launch(string homePageUrl, string browser = "ie")
        public static HomePage Launch(string homePageUrl, string browser)
        {
            // based on the browser passed in, created your web driver
            IWebDriver driver;

            if (browser.StartsWith("chrome"))
            {
                var chromeOptions = new ChromeOptions();

                if (browser.EndsWith("headless"))
                {
                    chromeOptions.AddArgument("--headless");
                }
                driver = new ChromeDriver(chromeOptions);
            }
            else if (browser.StartsWith("firefox"))
            {
                var firefoxOptions = new FirefoxOptions();

                if (browser.EndsWith("headless"))
                {
                    firefoxOptions.AddArgument("--headless");
                }

                driver = new FirefoxDriver(firefoxOptions);
            }
            else if (browser.StartsWith("edge"))
            {
                var edgeOptions = new EdgeOptions();

                driver = new EdgeDriver(edgeOptions);
            }

            else if (browser.Equals("phantomjs"))
            {
                driver = new PhantomJSDriver();
            }
            else
            {
                var ieOptions = new InternetExplorerOptions();
                ieOptions.IgnoreZoomLevel = true;

                driver = new InternetExplorerDriver(ieOptions);
            }

            // set the window size of the browser and browse to the home page
            driver.Manage().Window.Size = new Size(1366, 768);
            driver.Navigate().GoToUrl(homePageUrl);
            return(new HomePage(driver));
        }
コード例 #16
0
        public static void Process()
        {
            // works with local html page but has browser window
            //IWebDriver driver = new ChromeDriver();
            // not working with local html page
            IWebDriver driver = new PhantomJSDriver();

            driver.Navigate().GoToUrl("file://c:/Work/Workspace/SeleniumTutorialNet/SeleniumTutorialNet/empty-page.html");
            //driver.Navigate().GoToUrl("http://www.google.ca");
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));

            Console.WriteLine("\n\n" + driver.Title);
            //Console.WriteLine("\n\n" + driver.PageSource);
        }
コード例 #17
0
        static void AccessEuroNext()
        {
            List <Target> stockList = AccessFiles.getList(StockName.EURONEXT);

            foreach (var stock in stockList)
            {
                Console.WriteLine(stock.urlIdentifier);
            }
            GlobalQuote mytempQuery = AccessXIgnite.getXigniteData("XNAS", "a");

            using (PhantomJSDriver driver = new PhantomJSDriver(@"C:\phantomjs-2.1.1-windows\bin"))
            {
                foreach (Target stock in stockList)
                {
                    driver.Url = stock.urlIdentifier;
                    driver.Navigate();
                    System.Threading.Thread.Sleep(3 * 1000);
                    Instrument myInstrument = new Instrument();
                    {
                        try
                        {
                            myInstrument.PctChange(driver.FindElementById("cnDiffRelvalue").Text.Replace("(", string.Empty).Replace(")", string.Empty));
                            myInstrument.Change(driver.FindElementById("cnDiffAbsvalue").Text);
                            myInstrument.LastPrice(driver.FindElementById("lastPriceint").Text + driver.FindElementById("lastPricefract").Text);
                            myInstrument.DayHigh(driver.FindElementById("highPricevalue").Text.Split('[')[0]);
                            myInstrument.DayLow(driver.FindElementById("lowPricevalue").Text.Split('[')[0]);
                            string b = driver.FindElementById("todayVolumevalue").Text.Split('[')[0];
                            myInstrument.Volume(driver.FindElementById("todayVolumevalue").Text.Split('[')[0]);
                            //myInstrument.PrevClose(table.FindElement(By.ClassName("op")).Text);

                            myInstrument.Bid(driver.FindElementById("bidPricevalue").Text);
                            myInstrument.Ask(driver.FindElementById("askPricevalue").Text);

                            myInstrument.ticker            = stock.shortIdentifier;
                            myInstrument.timestamp         = System.DateTime.Now;
                            myInstrument.stockExchangeName = StockName.EURONEXT;
                            myInstrument.url = stock.urlIdentifier;
                        }

                        catch

                        {
                        }
                    }
                    InstrumentContext ctx = new InstrumentContext();
                    ctx.Instruments.InsertOne(myInstrument);
                }
            }
        }
コード例 #18
0
        void crawl(string number)
        {
            var driverService = PhantomJSDriverService.CreateDefaultService(Environment.CurrentDirectory);


            driverService.HideCommandPromptWindow = true;

            IWebDriver driver = new PhantomJSDriver(driverService);

            driver.Navigate().GoToUrl("https://www.truecaller.com/");

            try
            {
                //       ((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(@"E:\Haider\Haider\Beautiful Soup\img1.jpg", ScreenshotImageFormat.Jpeg);
                var set = driver.FindElement(By.ClassName("searchbar__query"));
                set.SendKeys("+" + number);
                var    button = driver.FindElement(By.ClassName("searchbar__submit"));
                string js     = "arguments[0].click();";

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

                Thread.Sleep(10);


                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

                string name          = "";
                string other_details = "";
                Loboloba.Text = "";
                foreach (var element in driver.FindElements(By.CssSelector("div.profile-name")))
                {
                    Loboloba.Text += name = element.Text + Environment.NewLine;
                }
                foreach (var element in driver.FindElements(By.CssSelector("div.profile-details-text")))
                {
                    Loboloba.Text += other_details = element.Text + Environment.NewLine;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            finally
            {
                driver.Close();
                driver.Quit();
            }
        }
コード例 #19
0
        private IWebDriver CreateDriver()
        {
            IWebDriver webDriver;

            switch (_driverConfiguration.TargetDriver)
            {
            case DriverNames.IE:
                webDriver = new InternetExplorerDriver(new InternetExplorerOptions()
                {
                    IgnoreZoomLevel = true,
                    IntroduceInstabilityByIgnoringProtectedModeSettings = true
                });
                break;

            case DriverNames.Firefox:
                var firefoxProfile = new FirefoxProfile();
                firefoxProfile.AddExtension(@"JSErrorCollector.xpi");
                if (!String.IsNullOrEmpty(DriverConfiguration.GetConfiguration().DownloadDir))
                {
                    firefoxProfile.SetPreference("browser.download.dir", DriverConfiguration.GetConfiguration().DownloadDir);
                    firefoxProfile.SetPreference("browser.helperApps.alwaysAsk.force", false);
                    firefoxProfile.SetPreference("browser.download.folderList", 2);
                    firefoxProfile.SetPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", false);
                    firefoxProfile.SetPreference("browser.download.useDownloadDir", true);
                    firefoxProfile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "image/png, application/vnd.ms-excel");
                }
                webDriver = new FirefoxDriver(firefoxProfile);
                break;

            case DriverNames.Chrome:
                webDriver = new OpenQA.Selenium.Chrome.ChromeDriver();
                break;

            case DriverNames.PhantomJS:
                var options = new PhantomJSOptions();
                options.AddAdditionalCapability("user-agent", PhantomUserAgent);
                webDriver = new PhantomJSDriver(options);
                break;

            case DriverNames.Safari:
                webDriver = new OpenQA.Selenium.Safari.SafariDriver();
                break;

            default:
                throw new NotImplementedException();
            }

            return(webDriver);
        }
コード例 #20
0
        public void SearchWeb()
        {
            var driver = new PhantomJSDriver();

            driver.Url = "http://ieeexplore.ieee.org/browse/conferences/title/";
            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 pathElement = driver.FindElementById("some-id");

            System.IO.File.WriteAllText(@"D:\Work\Dizertatie\Aplicatia\results.txt", source);
        }
コード例 #21
0
 public void TestPhantomJsExecutionTime()
 {
     Profile
     (
         "TestPhantomJsExecutionTime",
         10,
         () =>
     {
         using (IWebDriver driver = new PhantomJSDriver())
         {
             PerformTestOperations(driver);
         }
     }
     );
 }
コード例 #22
0
ファイル: Program.cs プロジェクト: Sanclayr/ScrapeData
        static void Main(string[] args)
        {
            IWebDriver driver = new PhantomJSDriver();

            var url = "http://en.wikipedia.org/wiki/Web_scraping";

            driver.Navigate().GoToUrl(url);

            var titles = driver.FindElements(By.CssSelector("#firstHeading"));

            var myFirstScrape = titles.First().Text;

            Console.WriteLine(myFirstScrape);
            Console.ReadLine();
        }
コード例 #23
0
        /// <summary>
        /// GetSubImage
        /// </summary>
        /// <param name="driver"></param>
        /// <param name="iWebElement"></param>
        /// <returns></returns>
        private static Image GetSubImage(PhantomJSDriver driver, IWebElement iWebElement)
        {
            var location   = iWebElement.Location;
            var x          = location.X;
            var y          = location.Y;
            var size       = iWebElement.Size;
            var width      = size.Width;
            var height     = size.Height;
            var screenshot = driver.GetScreenshot();
            //screenshot.SaveAsFile("c:/yuantu.png",ImageFormat.Png);
            var byteArray = screenshot.AsByteArray;
            var image     = GetSubImage(byteArray, x, y, width, height);

            return(image);
        }
コード例 #24
0
        private static string FetchPageContentByPhantomJS(string url, string phantomJsDriverPath)
        {
            var driver = new PhantomJSDriver(phantomJsDriverPath);

            try
            {
                driver.Navigate().GoToUrl(url);
                return(driver.PageSource);
            }
            finally
            {
                driver.Close();
                driver.Quit();
            }
        }
コード例 #25
0
        /// <summary>
        /// GetHtml
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string GetHtml(string url)
        {
            var userAgent =
                @"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.108 Safari/537.36 2345Explorer/8.6.2.15784";
            var options = new PhantomJSOptions();

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

            using (var driver = new PhantomJSDriver(options))
            {
                var navigation = driver.Navigate();
                navigation.GoToUrl(url);
                return(driver.PageSource);
            }
        }
コード例 #26
0
ファイル: PhantomJSExt.cs プロジェクト: raljoach/Apps
        public static PhantomJSDriver InitPhantomJS()
        {
            PhantomJSDriverService service = PhantomJSDriverService.CreateDefaultService();

            service.LogFile = @".\phantom.log";
            service.SuppressInitialDiagnosticInformation = true;
            int firstRow = Console.CursorTop;
            //var tmp = Console.Out;
            //Console.SetOut(new StringWriter(new StringBuilder()));
            PhantomJSDriver driver = new PhantomJSDriver(service);

            //Console.SetOut(tmp);
            ClearConsole(firstRow);
            return(driver);
        }
コード例 #27
0
ファイル: Program.cs プロジェクト: davnaz/FullTruliaParser
        void TestDriver()
        {
            string link   = "https://www.trulia.com/property-sitemap/AL/";
            var    driver = new PhantomJSDriver();

            driver.Manage().Window.Size = new Size(1920, 1080);
            driver.Navigate().GoToUrl(link);
            var links = driver.FindElementsByCssSelector("dl a");

            foreach (var a in links)
            {
                //Console.WriteLine("City: {0}, Link: {1}, Count: {2}", a.Text.Replace(a.Text.Split(' ')[0],String.Empty).Replace(" Homes",String.Empty), a.GetAttribute(Constants.WebAttrsNames.href), Int32.Parse(a.Text.Split(' ')[0].Replace(",",String.Empty)));
            }
            driver.Quit();
        }
コード例 #28
0
        /// <summary>
        /// Waits for the ajax call to complete then retuens, throws a timeout exception if the timeout period is exceeded.
        /// </summary>
        /// <param name="phantomDriver"></param>
        /// <param name="timeout">The number of seconds before a timeout exception is thrown.</param>
        internal static void WaitForAjax(this PhantomJSDriver phantomDriver, int timeout = 10)
        {
            var stopWatch = new Stopwatch();

            while (stopWatch.Elapsed.TotalSeconds < timeout)
            {
                var ajaxIsComplete = (bool)(phantomDriver as IJavaScriptExecutor).ExecuteScript("return jQuery.active == 0");
                if (ajaxIsComplete)
                {
                    return;
                }
            }

            throw new TimeoutException($"The request did not complete in the given timeout period of ({timeout} seconds.)");
        }
コード例 #29
0
        public RemoteWebDriver GetPhantomMobile(string url)
        {
            lock (lockThis2) {
                var options = new PhantomJSOptions();
                options.AddAdditionalCapability("phantomjs.page.settings.userAgent",
                                                @"Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0");

                var driver = new PhantomJSDriver(CoreConfiguration.WebDriversLocation, options)
                {
                    Url = url
                };
                driver.Navigate();
                return(driver);
            }
        }
コード例 #30
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //var webClient = new WebClient();
            //var form = new BasicHtmlForm(webClient);
            //form.Load(new Uri("http://www.weather.gov/"), new KeyValuePair<string, string>("name", "getForecast"));
            //form.InputControls.Single(c => c.Name == "inputstring").Value = "fairbanks, ak";

            //using (var response = form.Submit())
            //{
            //    if (response.ResponseType == WebResponseType.Html)
            //    {
            //        var scraper = new TestScraper(((HtmlWebResponse)response).Html);

            //        var conditions = scraper.GetConditions();

            //        var temperature = scraper.GetTemperature();
            //        System.Diagnostics.Debug.WriteLine(conditions);
            //        Weather.InnerText = temperature;

            //        var scraper2 = new TestScraper2(((HtmlWebResponse)response).Html);
            //        var craigslist = scraper2.GetList();
            //    }
            //}

            var webClient1 = new WebClient();
            var form1      = new BasicHtmlForm(webClient1);

            form1.Load(new Uri("https://www.trulia.com/rent/"), new KeyValuePair <string, string>("data-reactid", "29"));
            form1.InputControls.Single(c => c.Name == "location-autocomplete").Value = "Frisco, TX";
            using (var response = form1.Submit())
            {
                if (response.ResponseType == WebResponseType.Html)
                {
                    var scraper2 = new TestScraper2(((HtmlWebResponse)response).Html);

                    // var craigslist = scraper2.GetList();
                    // Weather.InnerText = craigslist;
                }
            }


            IWebDriver driver = new PhantomJSDriver();

            driver.Navigate().GoToUrl("https://twitter.com/Twitter");
            var backpack  = driver.Title;
            var back      = driver.FindElement(By.XPath("//*[@class='u-linkComplex-target']"));
            var backpack2 = driver.FindElement(By.XPath("//*[contains(@class,'twitter-timeline-link')]/span[2]"));
        }