Fetching Saved Links in reddit.com

Been saving a lot of links in reddit.com and wanted to start from the beginning. Having been lazy in reaching to the first saved link manually, I wrote a small perl script to output all the next links:

#!/usr/bin/perl -w

use LWP::UserAgent;

$ua = LWP::UserAgent->new;
$ua->agent("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16");

$begin_url = "http://www.reddit.com";

$url = $begin_url . "/saved";
while (1) {
print "Fetching $url\n";

my $req = HTTP::Request->new(GET => $url);
$req->header(Accept => "text/xml,application/xml,application/xhtml+xml,text/html");
$req->header("Accept-Language" => "en-us,en;q=0.5");
$req->header("Accept-Charset" => "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
$req->header("Keep-Alive" => "300");
$req->header("Connection" => "keep-alive");
$req->header("Cookie" => "reddit_first=first; reddit_session=XXXXX");

my $res = $ua->request($req);

if ($res->is_success) {
if ($res->content =~ m/\/saved?\?count=[0-9]+\&(amp=&)*after=[a-z_0-9]+/g) {
$url = $begin_url . $&;
} else {
print "Match not found...\n";
last;
}
} else {
print "Unable to fetch $url: $res->status_line, \n";
last;
}
}

Been struggling for a while to get syntax highlighting for my code. Finally found a couple of links that get this going. But the sad thing is that perl is not supported. 😦

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s