GetScreenshot() public méthode

Gets a Screenshot object representing the image of the page on the screen.
public GetScreenshot ( ) : Screenshot
Résultat Screenshot
        private string ExecuteCommand(string url)
        {
            try
            {

                using (var phantom = new PhantomJSDriver())
                {
                    var indexFile = Server.MapPath("~/Scripts/PhantomJS/index.js");
                    var scriptSource = System.IO.File.ReadAllText(indexFile);
                    var script = phantom.ExecutePhantomJS(scriptSource);

                    phantom.Navigate().GoToUrl("https://www.bing.com");

                    phantom.FindElement(By.Id("sb_form_q")).SendKeys("learn2automate");

                    //Click on Search
                    phantom.FindElement(By.Id("sb_form_go")).Click();

                    Screenshot sh = phantom.GetScreenshot();
                    sh.SaveAsFile(@"C:\Temp.jpg", ImageFormat.Png);

                    phantom.Quit();
                }

            }
            catch (Exception ex)
            {
            }

            return string.Empty;
        }
 private void GenerateScreenShot(Guid guid, PhantomJSDriver driver)
 {
     try
     {
         if (driver.PageSource != "<html><head></head><body></body></html>"
             && !driver.PageSource.Contains("Congratulations. This browser is configured to use Tor.")
             && !driver.PageSource.Contains("reddit404a.png")
             && !driver.PageSource.Contains("403 Forbidden")
             && !driver.PageSource.Contains("404 Not Found")
             && !driver.PageSource.Contains("Page not found")
             && !driver.PageSource.Contains("elgg-state-error"))
         {
             //temporary until I can figure how the f* to get the bytearray to write to a stream
             driver.GetScreenshot().SaveAsFile(String.Format(@"C:\torimages\x{0}.tiff", guid.ToString()), System.Drawing.Imaging.ImageFormat.Tiff);
             NewMessage(String.Format("Image saved of {0}", ScanObject.Name), false);
         }
         else
         {
             NewMessage(String.Format("{0} Contains invalid html. No Screenshot avialable.", this.ScanObject.Name), true);
         }
     }
     catch
     {
         ScanObject.Description = "Error while creating screenshot - Aborting...";
         ScanObject.PageStatus = "ERROR";
         ScanObject.Update();
     }
 }
Exemple #3
0
        public void ScrapeAdds(string url)
        {
            var service = PhantomJSDriverService.CreateDefaultService();
             service.HideCommandPromptWindow = true;

            var driver = new PhantomJSDriver(service);
            List<string> categories = new List<string>();
            List<string> Links = new List<string>();
            List<string> Images = new List<string>();
            List<string> Titles = new List<string>();
            service.IgnoreSslErrors = true;
            service.LoadImages = false;
            service.ProxyType = "none";
            try
            {
                driver.Navigate().GoToUrl(url);
                driver.GetScreenshot().SaveAsFile("image1.png", ImageFormat.Png);
                IWebElement body = driver.FindElement(By.TagName("head"));
                //IWebElement body = driver.FindElement(By.TagName("body"));
                //string pageSource = body.ToString();
                ReadOnlyCollection<IWebElement> getCategories = driver.FindElements(By.XPath("//ul[@id='menu-menu_main']/li/a"));
                foreach(var cat in getCategories)
                {
                    string s1 = cat.GetAttribute("href").ToString();
                    categories.Add(s1);
                }

                foreach (var catUrl in categories)
                {
                    driver.Navigate().GoToUrl(catUrl);
                    ReadOnlyCollection<IWebElement> pgNumber = driver.FindElements(By.XPath("//span[@class='pages']"));
                    string pgnum = pgNumber[0].GetAttribute("outerText");
                    int pageNumber = int.Parse(pgnum.Split(' ')[3]);
                    for (int i = 1; i < pageNumber; i++)
                    {
                        string categUrl = catUrl;
                        driver.Navigate().GoToUrl(categUrl);
                        ReadOnlyCollection<IWebElement> urls = driver.FindElements(By.XPath("//a[@itemprop='url']"));
                        ReadOnlyCollection<IWebElement> image = driver.FindElements(By.XPath("//img[@class='entry-thumb']"));
                        foreach (var v1 in urls)
                        {
                            string link = v1.GetAttribute("href");
                            string title = v1.GetAttribute("title");
                            string img = v1.GetAttribute("src");
                            Links.Add(link);
                        }

                        foreach (var v2 in image)
                        {

                            string img = v2.GetAttribute("src");
                            Images.Add(img);
                        }
                        categUrl=categUrl+  "page / "+i+"/";

                    }

                }

            }
            catch(Exception ex)
            { }
        }