Tools to Capture and Convert the Web

GrabzIt Handler with Perl

Perl API

Description

Having problems debugging your handler? Try the Callback Handler Test Tool.

The handler described here processes callbacks from the GrabzIt screenshot web service. The URL of this handler is passed to GrabzIt in the callBackURL parameter of the Save method. However this technique will only work if the handler is accessible via the Internet.

The following parameters are passed to the handler as GET parameters.

If you want to block all access to the handler, except from GrabzIt then use this security technique.

Example

Remember this callback will not work if your application is located on localhost.

This example shows how the GrabzIt Perl handler can be implemented. This captures six parameters passed to it from the GrabzIt service, including the unique id of the screenshot which is passed to the GetResult method.

This method then returns the screenshot, which is saved in the results directory. However if a null value is returned from the GetResult method this indicates that an error has occured.

use CGI;
use CGI::Carp qw(warningsToBrowser fatalsToBrowser); 
use File::Spec;
use GrabzIt::GrabzItClient;

# This Perl file handles the GrabzIt callback

print "HTTP/1.0 200 OK";
print "Content-type: text/html\r\n\r\n";

$cgi = new CGI;

$message = $cgi->param("message");
$customId = $cgi->param("customid");
$id = $cgi->param("id");
$filename = $cgi->param("filename");
$format = $cgi->param("format");
$targetError = $cgi->param("targeterror");

# Custom id can be used to store user ids or whatever is needed for the later processing of the
# resulting screenshot

$grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret")%>");
$result = $grabzIt->GetResult($id);

if ($result)
{
        # Ensure that the application has the correct rights for this directory.
        open FILE, ">".File::Spec->catfile("results",$filename) or die $!; 
        binmode FILE;
        print FILE $result; 
        close FILE;
}