Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am currently working on a script and have came to a complete halt. My script is designed to login to my Deviant Art account and download all my artwork. I have got almost all of the script pretty much working, except for the logging in part. I have been using the LWP package, which has worked well up until now.

So I was hoping that someone would be able to show and/or explain how to log into the site and access pages that can only be viewed while logged in.

Thank you for your time.

For those who like a visual reference this is the login page (click here)

Replies are listed 'Best First'.
Re: Login script for da.
by james2vegas (Chaplain) on Aug 23, 2009 at 00:00 UTC
    That url is not what you think it is, it goes to 404. Sadly that page is generated from the previous page at http://www.deviantart.com. Anyway get the action and method of the page, and the names of the login fields and send them in a POST method. You may consider using WWW::Mechanize as it makes this a little bit easier.

    The form is a POST, and you should probably pass in the username, password, ref (set to http://www.deviantart.com), and reusetoken (set to 1) fields to the form which is https://www.deviartart.com/users/login/). You'll need to store the cookies from that transaction and pass them along with any requests you make to other pages.
    use strict; use warnings; use LWP; use HTTP::Request::Common qw(POST); my $cookies = {}; my $ua = LWP::UserAgent->new( cookie_jar => $cookies, agent => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT +5.1'); my $req = POST 'https://www.deviantart.com/users/login', [ username => $mydauser, password => $mydapass, reusetoken => 1, ref => 'http://www.deviantart.com']; my $response = $ua->request($req); print $response->content;
    This is how it should work,, you may need to set a proper User Agent and such. I have also arranged for a cookie-jar to store your cookies. See LWP::UserAgent for more details.

    Update: I changed the target of the POST to be https://www.deviantart.com/users/login from https://www.deviantart.com/users/login/ as login/ returned 404.