use warnings; use strict; use Encode;die "wrong parameter" unless (@ARGV == 1); die "cannot find file" unless (-e $ARGV[0]);
my $rootdir = "./imported"; mkdir $rootdir;
my $currentdir = $rootdir;
open(BOOKMARK, $ARGV[0]); while (<BOOKMARK>) { if (/<DT><H3.*>(.*)</H3>/) { $currentdir = $rootdir . "/$1"; mkdir $currentdir; print "$1 "; } if (/<DT><A HREF="(.*)" ADD_DATE=.*>(.*)</A>/) { my $name = decode("utf-8", $2); my $link = $1; $name = encode("euc-cn", $name); $name =~ s/[:,/?.=]/_/g; print " $name "; $name = $currentdir . "/$name.url"; open(LNK, ">$name"); print LNK "[InternetShortcut] URL=$link "; close(LNK); } } close(BOOKMARK);
以前还用python写过一个opera到ie的,顺便也贴上来吧,这个脚本对中文处理的不好,没有做utf8->gb2312的转换。
import os
FOLDER_START = 1 URL_START = 2 NONE = 3
def createLink(linkName, linkURL): try: linkName = linkName.replace(":", "_") linkName = linkName.replace("?", "_") linkFile = open(linkName, "w") linkFile.write("[InternetShortcut] ") linkFile.write("URL=" + linkURL + " ") linkFile.close() except: print "Occur error while create " + linkName + " linked to " + linkURL
def createDir(dirName): if os.access(dirName, os.F_OK) == 0: os.mkdir(dirName)
baseDir = "OperaAddress/" createDir(baseDir) file = open("opera6.adr", "r") lines = file.readlines() currentDir = baseDir step = NONE linkName = "" linkURL = "" for line in lines: line = line.strip() if line == "#FOLDER": step = FOLDER_START elif line == "#URL": step = URL_START elif line == "-": r = currentDir.rindex("/", 0, -2) currentDir = currentDir[0:r + 1] print currentDir else: kv = line.split("=", 1) if len(kv) != 2: continue key = kv[0] value = kv[1] if key == "NAME": if step == FOLDER_START: currentDir = currentDir + value + "/" createDir(currentDir) elif step == URL_START: linkName = value elif key == "URL": if step == URL_START: linkURL = value createLink(currentDir + linkName + ".url", linkURL)