Tools to Capture and Convert the Web

How to wait for a web page to load before performing a capture?

An item on a webpage loading after the main content

Some webpages can take a while to load or have specific content you are interested in that may load after the main page has loaded. This is especially true on AJAX heavy web pages were content is loaded via JavaScript.

GrabzIt detects when a webpage loads but for some of the specific circumstances listed above it needs some additional instructions in the form of a delay that should be used before the capture is taken or by waiting for a specified HTML element to appear before the capture should go ahead. These techniques can be used if you are taking screenshots of webpages or converting HTML into PDF’s, images or Word documents, and you have a premium package. Although you can try these features for free with our seven day free trial.

These features are also available in our online screenshot and web scraper tools.

How to wait for a specified time before performing a capture?

Just specify the delay in milliseconds and this is how long the capture will wait for. Remember that there are 1000 milliseconds in a second. All of the below examples wait three seconds before capturing the webpage.

GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
ImageOptions options = new ImageOptions();
options.Delay = 3000;
grabzIt.URLToImage("http://www.google.com", options);
grabzIt.SaveTo("images/result.jpg");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
ImageOptions options = new ImageOptions();
options.setDelay(3000);
grabzIt.URLToImage("http://www.google.com", options);
grabzIt.SaveTo("images/result.jpg");
<script src="https://cdn.jsdelivr.net/gh/GrabzIt/grabzit@js-3.2.9.9/javascript/grabzit.min.js"></script>
<script>
GrabzIt("Sign in to view your Application Key").ConvertURL("http://www.google.com", 
{"delay": 3000}).Create();
</script>
var grabzit = require('grabzit');

var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret");
var options = {"delay":"3000"};
client.url_to_image("http://www.google.com", options);
client.save_to("images/result.jpg", function (error, id){
    if (error != null){
        throw error;
    }
});
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");
$options = GrabzItImageOptions->new();
$options->delay(3000);
$grabzIt->URLToImage("http://www.google.com", $options);
$grabzIt->SaveTo("images/result.jpg");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
$options = new \GrabzIt\GrabzItImageOptions();
$options->setDelay(3000);
$grabzIt->URLToImage("http://www.google.com", $options);
$grabzIt->SaveTo($filepath);
grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret")
options = GrabzItImageOptions.GrabzItImageOptions()
options.delay = 3000
grabzIt.URLToImage("http://www.google.com", options)
grabzIt.SaveTo("images/result.jpg")
grabzIt = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")
waitForElementoptions = GrabzIt::ImageOptions.new()
options.delay = 3000
grabzItClient.url_to_image("http://www.google.com", options)
grabzItClient.save_to("images/result.jpg")

How to wait for a HTML element to appear before performing a capture?

This technique is especially useful on webpages that use AJAX methods to load content. First use your browsers developer tools to identify the element that you need to wait to appear for, take a note of its id or class. Then specify this class or ID as a standard CSS selector and once the element becomes visible the web page is captured. Note that if there are multiple matching HTML elements it will appear as soon as one is visible.

GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
ImageOptions options = new ImageOptions();
options.WaitForElement = "#Content";
grabzIt.URLToImage("http://www.google.com", options);
grabzIt.SaveTo("images/result.jpg");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
ImageOptions options = new ImageOptions();
options.setWaitForElement("#Content");
grabzIt.URLToImage("http://www.google.com", options);
grabzIt.SaveTo("images/result.jpg");
<script src="https://cdn.jsdelivr.net/gh/GrabzIt/grabzit@js-3.2.9.9/javascript/grabzit.min.js"></script>
<script>
GrabzIt("Sign in to view your Application Key").ConvertURL("http://www.google.com", 
{"waitfor": "#Content"}).Create();
</script>
var grabzit = require('grabzit');

var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret");
var options = {"waitForElement":"#Content"};
client.url_to_image("http://www.google.com", options);
client.save_to("images/result.jpg", function (error, id){
    if (error != null){
        throw error;
    }
});
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");
$options = GrabzItImageOptions->new();
$options->waitForElement("#Content");
$grabzIt->URLToImage("http://www.google.com", $options);
$grabzIt->SaveTo("images/result.jpg");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
$options = new \GrabzIt\GrabzItImageOptions();
$options->setWaitForElement("#Content");
$grabzIt->URLToImage("http://www.google.com", $options);
$grabzIt->SaveTo($filepath);
grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret")
options = GrabzItImageOptions.GrabzItImageOptions()
options.waitForElement = "#Content"
grabzIt.URLToImage("http://www.google.com", options)
grabzIt.SaveTo("images/result.jpg")
grabzIt = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")
options = GrabzIt::ImageOptions.new()
options.waitForElement = "#Content"
grabzItClient.url_to_image("http://www.google.com", options)
grabzItClient.save_to("images/result.jpg")
Back to Support
Try all our premium features for free with a 7 day free trial. Then from $5.99 a month, unless cancelled.
  • More Captures
  • More Features
  • More API's
  • Bigger Scrapes
  • Bigger Captures
  • Bigger Everything
Start Free Trial