The Code
This script logs into Yahoo! and fetches your exported bookmarks. From there, it goes through the bookmarks line by line, adding folder names and links to a filename you specify in $file. Be sure to replace the $user and $pass values with your Yahoo! username and password so that the script can log in on your behalf. Create a file called getBookmarks.pl and add the following code:
#!/usr/bin/perl
# getBookmarks.pl
# A script to download Yahoo! Bookmarks and format them as HTML
# Usage: getBookmarks.pl
use WWW::Yahoo::Login qw( login logout );
use WWW::Mechanize;
use strict;
# Set some user variables
my $user = "insert Yahoo! ID";
my $pass = "insert Yahoo! Password";
my $file = "links.html";
my $bookmarkurl = "http://bookmarks.yahoo.com/config/";
$bookmarkurl .= "export_bookmark?.commit=1";
my $mech = WWW::Mechanize->new( );
# Log into Yahoo!
my $resp = login(
mech => $mech,
uri => $bookmarkurl,
user => $user,
pass => $pass,
);
# If login succeeded, loop through the HTML
if ($resp) {
print "Login ok!\n";
my $bookmarks = $mech->content;
my @bookmarks = split(/\n/, $bookmarks);
# Open the output file
open FILE, "> $file" or die "Can't open $file : $!";
# Loop through the bookmarks, printing to file
foreach my $line (@bookmarks) {
# If the line is folder, print it
if ($line =~ m!<H3[^>].*>(.*?) </H3>!gi) {
print FILE "<div class=\"folder\">";
print FILE $1;
print FILE "</div>\n";
}
# If the line is a bookmark, print it
if ($line =~ m!<A HREF="([^"]+)"[^>]+>(.*?)</A>!gi) {
print FILE "<div class=\"link\">";
print FILE "<a href=\"$1\">$2</a>";
print FILE "</div>\n";
}
}
# Close the output file
close FILE;
} else {
warn $WWW::Yahoo::Login::ERROR;
}