use strict; use warnings; use WWW::Mechanize; use Data::Dumper; my $user = 'foo'; my $pass = 'bar'; my $mech = WWW::Mechanize->new(); my $response = $mech->get('http://safari.oreilly.com/login'); die "Failed to load login page: " + $response->message unless $response->is_success; $mech->form_number(1); $mech->set_visible($user,$pass); $response = $mech->submit(); die "Failed to login: " + $response->message unless $response->is_success; # TODO - Check the page content here for a failed login message # Find the link to the bookshelf, and follow it $mech->follow_link(url_regex => qr/mybookshelf/); # Get a list of all links, then limit the list to those that are /numeric my @links = $mech->links(); my @books = grep {$_->url =~ /^\/\d+$/} @links; for my $book (@books) { my $isbn = $book->url; $isbn =~ s//^\//; printf "ISBN: %s Title: %s\n", $isbn, $book->text; }