Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!usr/bin/perl
- #shitty web scraper in perl
- #use strict;
- use warnings;
- use LWP 5.64;
- use HTTP::Cookies;
- sub main
- {
- printf("What site would you like to scrape? (Please enter the full URL [I.E https://rms.org])");
- my $url = <>;
- my $ua = LWP::UserAgent->new();
- my $cookies = HTTP::Cookies->new
- (
- file => "cookies.txt", autosave => 1,
- );
- $ua->cookie_jar($cookies);
- $ua->agent("Windows IE 7");
- my $response = $ua->get($url);
- unless($response->is_success)
- {
- warnings::warn("URL invalid - got " . $response->status_line . "\n")
- }
- unless ($response->content_type eq 'text/html')
- {
- printf("Expected HTML, got " . $response->content_type . "\n");
- }
- my $saved_content = "saved.html";
- unless (open SAVED_CONTENT, '>'. $saved_content)
- {
- printf("Can not create $saved_content");
- }
- binmode(SAVED_CONTENT, "utf:8");
- printf(SAVED_CONTENT $response->decoded_content);
- close SAVED_CONTENT;
- printf("Saved " . $response->decoded_content . "of data");
- }
- main();
Add Comment
Please, Sign In to add comment