Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use warnings;
- use strict;
- use utf8;
- use LWP::UserAgent;
- # get the file via ARGV
- die "Please point to a text file with links in the 1st argument!\n" unless $ARGV[0];
- my $csv_filename = $ARGV[0];
- # open the file; should be a plain text file; one url per line
- open(my $csv_FH, '<:encoding(utf8)', $csv_filename) or die $!;
- # instantiate a UserAgent
- my $ua = LWP::UserAgent->new(
- # set a fake Browser UserAgent string :)
- agent => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36',
- # set a timeout in seconds
- timeout => 10
- );
- # read the file
- while (<$csv_FH>) {
- # chop off the new line feed
- chomp;
- # check if vaild URL
- next unless $_ =~ /^(?:[a-z0-9\-\._~!\$&'\(\)\*+,;=:\/?@]|%[0-9A-F]{2})*$/i;
- # trim the URL
- $_ =~ s/^\s+|\s+$//g;
- # get it
- my $website = $ua->get($_);
- # remove it from memory
- undef($website);
- }
- close($csv_FH);
- exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement