use strict;
use warnings;
# Initialize variables to store extracted URLs
my @google_maps_urls;
# Process each HTML file (1.html to 25.html)
for my $file_number (1..25) {
my $input_file = "${file_number}.html";
# Open the current input file for reading
open my $input_fh, '<', $input_file or warn "Cannot open input file '$input_file': $!";
# Read each line and look for URLs
while (my $line = <$input_fh>) {
chomp $line;
if ($line =~ /https:\/\/www\.google\.com\/maps\/place/) {
# Remove leading '<' and trailing '>'
$line =~ s/^<(.+)>$/$1/;
push @google_maps_urls, $line;
}
}
# Close the current input file
close $input_fh;
}
# Save the extracted URLs to a file
my $output_file = 'extracted.txt';
open my $output_fh, '>', $output_file or die "Cannot open output file '$output_file': $!";
foreach my $url (@google_maps_urls) {
print $output_fh "$url\n";
}
# Close the output file
close $output_fh;
print "Extraction complete. Extracted URLs are saved in '$output_file'\n";