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 web pages or converting HTML into PDF’s, images or Word documents, and you have a premium package. However both techniques are limited to a maximum wait time of thirty seconds.

It is a good idea to not use a too large a delay because in the unusual event of captures being queued a large delay will reduce the capture priority, although there is some clever work arounds to this.

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.spacex.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.spacex.com", options);
grabzIt.SaveTo("images/result.jpg");
<script src="https://cdn.jsdelivr.net/npm/@grabzit/js@3.5.2/grabzit.min.js"></script>
<script>
GrabzIt("Sign in to view your Application Key").ConvertURL("http://www.spacex.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.spacex.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.spacex.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.spacex.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.spacex.com", options)
grabzIt.SaveTo("images/result.jpg")
https://api.grabz.it/services/convert?key=Sign in to view your Application Key&format=jpg&delay=3000&url=https%3A%2F%2Fspacex.com%2F
grabzIt = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")
options = GrabzIt::ImageOptions.new()
options.delay = 3000
grabzItClient.url_to_image("http://www.spacex.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, class or make a more complicated CSS selector. Then specify this 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.spacex.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.spacex.com", options);
grabzIt.SaveTo("images/result.jpg");
<script src="https://cdn.jsdelivr.net/npm/@grabzit/js@3.5.2/grabzit.min.js"></script>
<script>
GrabzIt("Sign in to view your Application Key").ConvertURL("http://www.spacex.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.spacex.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.spacex.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.spacex.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.spacex.com", options)
grabzIt.SaveTo("images/result.jpg")
https://api.grabz.it/services/convert?key=Sign in to view your Application Key&format=jpg&waitfor=%23Content&url=https%3A%2F%2Fspacex.com%2F
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.spacex.com", options)
grabzItClient.save_to("images/result.jpg")

This technique can be used in conjunction with the delay method mentioned first. Allowing you to wait for a HTML element to appear and then wait for a further period of time before creating the capture.