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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| #!/usr/bin/env perl
use strict;
use utf8;
use encoding 'utf8';
use warnings qw(all);
use Data::Dumper;
use Encode;
use LWP;
ActiverAccents();
sub ActiverAccents {
my $encodage;
# Windows
if ( lc($^O ) eq 'mswin32') {
eval {
my ($codepage) = ( `chcp` =~ m/:\s+(\d+)/ );
$encodage = "cp$codepage";
foreach my $h ( \*STDOUT, \*STDERR, \*STDIN, ) {
binmode $h, ":encoding($encodage)";
}
};
}
else {
$encodage = `locale charmap`;
eval {
foreach my $h ( \*STDOUT, \*STDERR, \*STDIN, ) {
binmode $h, ":encoding($encodage)";
}
};
}
return $encodage;
}
my $href;
my @ligne;
my $a;
my $url = 'http://export.openstreetmap.fr/contours-administratifs/communes/';
my $ua = LWP::UserAgent->new;
$ua->agent( 'Mozilla/5.0' );
my $response = $ua->get( $url );
my $content = $response->content;
$content = decode( 'utf-8', $content ); # la page est en utf-8, alors on decode l'utf-8
# print Dumper($content);
@ligne = split(/\n/,$content);
foreach $a (@ligne){
# print $a."\n";
my @RepT = split /gz\">/, $a;
if ( $RepT[1] ) {
# print $RepT[1] ."\n";
@RepT = split /<\/a><\/td>/, $RepT[1];
my $url_shp = "http://export.openstreetmap.fr/contours-administratifs/communes/".$RepT[0];
print $url_shp."\n";
}
} |
Partager