Skip navigation.
Home

Example Code Perl

When I run this it looks like:

$ perl test.pl 
SUCCESS: captcha_id=17B30BBC-6B66-42CC-0AA3-70B55A4E9402
GOT CAPTCHA ID: 17B30BBC-6B66-42CC-0AA3-70B55A4E9402
ATTEMPT 1
WAIT: check back later
ATTEMPT 2
SUCCESS: captcha_result="DMJDxRw"

Here is the source code of that test client:

require LWP::UserAgent;
use Data::Dumper;

my $ua = LWP::UserAgent->new;
push @{ $ua->requests_redirectable }, "POST";

my $api_key = "insert_your_api_code_here";
my $captcha_url = "http://www.website.com/captcha_url";
my $upload_filename = "captcha_filename_on_disk";

my $response = $ua->post( "http://www.captchakiller.com/api.php",
                Content_Type => 'form-data',
                Content => [ api_key => $api_key, method => "upload_captcha",
                captcha_url => $captcha_url, file => [ $upload_filename ] ] );
$captcha_id = "";
if ( $response->is_success ) {
        print $response->{_content};
        if ( $response->{_content} =~ /SUCCESS: captcha_id=([\w\-]+)/ ) {
                $captcha_id = $1;
                print "GOT CAPTCHA ID: $captcha_id\n";
        }
}
else {
        die $response->status_line;
}

$captcha_result = "";
for ( my $cnt = 1; $cnt < 20; $cnt++ ) {
        print "ATTEMPT $cnt\n";
        my $response = $ua->post( "http://www.captchakiller.com/api.php",
                Content => [ api_key => $api_key, method => "get_result", captcha_id => $captcha_id ] );
        if ( $response->is_success ) {
                print $response->{_content};
                next if ( $response->{_content} =~ /^WAIT/ );
                last if ( $response->{_content} =~ /^FAILURE/ );
                if ( $response->{_content} =~ /^SUCCESS: captcha_result=\"(.*)\"$/ ) {
                        $captcha_result = $1;
                        last;
                }
        }
        else {
                die $response->status_line;
        }
}