aboutsummaryrefslogtreecommitdiff
path: root/svgcaptcha-parser
blob: fd65c8da7dd84c300adc86f6783225f495156b2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env perl

use strict;
use warnings;

use XML::Simple;
use HTTP::Tiny;

# Fetch fresh svg and parse it
my $response = HTTP::Tiny->new->get('http://svgcaptcha.com/captcha.php') or die("Failed to download new SVG: $!\n");
my $raw_svg = $response->{content};
my $svg = XMLin($raw_svg, KeyAttr => {"text", "x"})->{"text"};


# Build the filename
my $filename = "";
foreach my $i (sort {$a <=> $b} keys %$svg)
{
	$filename .= %$svg{$i}->{"content"};
}

# Write to file
open(my $f, ">", "$filename.svg") or die("Failed to open $filename.svg: $!\n");
print($f $raw_svg) or die("Failed to write to file: $!\n");
print("Saved $filename.svg\n");
close($f);