Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- # Download all FetLife pictures from a profile.
- #
- # Usage instructions:
- # * Fill in the constants.
- # * Make a folder named "images".
- # * Run the script.
- use strict;
- use warnings;
- use WWW::Mechanize;
- use constant {
- USERNAME => 'username',
- PASSWORD => 'password',
- USERID => 'fetlife-userid'
- };
- my $mech = WWW::Mechanize->new();
- main($mech);
- sub login {
- my $mech = shift;
- $mech->get('https://fetlife.com/login');
- $mech->submit_form(
- with_fields => {
- 'nickname_or_email' => USERAME,
- 'password' => PASSWORD
- }
- );
- }
- sub getPicturesOf {
- my $mech = shift;
- my $uid = shift;
- $mech->get("https://fetlife.com/users/$uid/pictures");
- my $next = $mech->find_link(text_regex => qr/Next /);
- while (defined($next)) {
- $next = $next->url;
- downloadPictures($mech, $uid);
- $mech->get("https://fetlife.com/$next");
- $next = $mech->find_link(text_regex => qr/Next /);
- }
- downloadPictures($mech, $uid);
- }
- sub downloadPictures {
- my $mech = shift;
- my $uid = shift;
- my @images = $mech->find_all_images(url_regex => qr{https://flpics\d.a.ssl.fastly.net/\d+/$uid/});
- map {
- my $imgurl = $_->url;
- $imgurl =~ s/\d+\.jpg$/720.jpg/;
- if ($imgurl =~ m{/([^/]+)$}) {
- print "Downloading $1\n";
- $mech->get($imgurl, ":content_file" => "images/$1");
- } else {
- print "No go.\n";
- }
- } @images;
- }
- sub main {
- my $mech = shift;
- login($mech);
- getPicturesOf($mech, USERID);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement