Unfortunately safari doesn't play well with others and uses javascript redirects when loading the login page, and after submitting the login request. They also use somewhat obfuscated javascript to hide their actions in a few places, which hints at them not wanting you to do this.

I would read over their terms of service and make sure this is not an action that will get your accounts terminated. At a glance it seems ok, but best to be cautious. It might be prudent to ask them, but the answer will likely be "don't do that".

If not for the above mentioned issues my first inclination is to use WWW::Mechanize to automate the login and navigation, as it combines HTTP, html parsing, form population/submission, and link extraction.

The links on the safari bookshelf page seem to be a forward slash followed by a numeric ISBN. So "Perl and LWP", with ISBN 0-596-00178-9, is "/0596001789".

An example of how you could go about solving this problem, if not for the javascript and legality issues, would be something like the following:

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 $respon +se->is_success; $mech->form_number(1); $mech->set_visible($user,$pass); $response = $mech->submit(); die "Failed to login: " + $response->message unless $response->is_suc +cess; # 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 /nume +ric 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; }
Update - It might be worth looking at safari enterprise offerings.

In reply to Re: Getting user stats from Safari by imp
in thread Getting user stats from Safari by carcassonne

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.