Select Git revision
rejskol-download
-
Martin Mareš authoredMartin Mareš authored
rejskol-download 1.53 KiB
#!/usr/bin/perl -CSA
use common::sense;
use WWW::Mechanize;
my $mech = WWW::Mechanize->new(autocheck => 1, strict_forms => 1);
$mech->get('https://rejstriky.msmt.cz/rejskol/VREJVerejne/VerejneRozhrani.aspx');
$mech->form_id('form1');
mkdir 'extra/skoly/html';
download_type('B'); # Základní školy
download_type('C'); # Střední školy
exit 0;
sub download_type {
my ($type) = @_;
my @regions = $mech->find_all_inputs(name => 'ctl39');
for my $in (@regions) {
my @vals = $in->possible_values;
my @names = $in->value_names;
if (my ($nuts) = ($names[1] =~ m{^(CZ\d{3}[0-9A-Z]),})) {
# Okres
download_region($type, $nuts, $vals[1]);
}
}
}
sub download_region {
my ($type, $nuts, $reg_val) = @_;
print "Downloading type=$type region=$nuts ($reg_val)\n";
my @types = $mech->find_all_inputs(name => 'ctl38');
for my $in (@types) {
my @vals = $in->possible_values;
# print $in->name, " ", $in->type, " ", join("|", @vals), "\n";
if ($vals[1] eq $type) {
$in->value($vals[1]);
} else {
$in->value($vals[0]);
}
}
my @regions = $mech->find_all_inputs(name => 'ctl39');
for my $in (@regions) {
my @vals = $in->possible_values;
# print $in->name, " ", $in->type, " ", join("|", @vals), "\n";
if ($vals[1] =~ $reg_val) {
$in->value($vals[1]);
} else {
$in->value($vals[0]);
}
}
$mech->field('txtPocetZaznamu', '1000');
sleep 1;
my $resp = $mech->click_button(id => 'btnVybrat');
open my $f, '>:utf8', "extra/skoly/html/$type-$nuts.html";
print $f $resp->decoded_content;
close $f;
$mech->back;
}