快速和脏的方式来解析一个mozilla firefox json文件

时间:2010-11-18 05:02:56

标签: json firefox bookmarks

我想从firefox创建的.json书签备份中删除所有url,并输出.txt文件。

以下是文件中一个对象的示例:

{"index":1,"title":"Bookmarks Toolbar","id":3,"parent":1,"dateAdded":1219177758531250,"lastModified":1288873459187000,"annos":[{"name":"bookmarkProperties/description","flags":0,"expires":4,"mimeType":null,"type":3,"value":"Add bookmarks to this folder to see them displayed on the Bookmarks Toolbar"}],"type":"text/x-moz-place-container","root":"toolbarFolder","children":[{"title":"","id":25,"parent":3,"dateAdded":1224693644437500,"lastModified":1236888979406250,"annos":[{"name":"placesInternal/GUID","flags":0,"expires":4,"mimeType":null,"type":3,"value":"{f6066e21-10ff-46a2-af7a-2891f8dca345}0"}],"type":"text/x-moz-place","uri":"http://www.google.com/"}

这些对象以逗号分隔,应该都包含至少一个包含字符串的成员,该字符串的值是书签的url。

以下是.txt文件中的内容示例:

http://www.google.com
http://www.yahoo.com
http://www.etc.com`

理想情况下,我很想知道是否可以使用通用Windows XP“环境”中提供的任何脚本工具来解决这个问题。

如果Windows无法削减它,最快的是什么?最简单的解决方案?

是否有网站或程序可以进行模式匹配或正则表达式来解析文件搜索&在我安装Active Perl或Strawberry Perl之前替换它并为其编写脚本。

3 个答案:

答案 0 :(得分:2)

我发现的另一种方法是以下网站的方法:

http://forums.mozillazine.org/viewtopic.php?f=38&t=1057265&sid=66d981cc79d1ff63644e0cdd5b665a37

基本上,您可以执行以下操作:

(1)创建一个firefox书签,其中包含以下位置:

javascript:(function(){var E=document.getElementsByTagName('PRE')[0],T=E.innerHTML,i=0,r1,r2;t=new Array();while(/("uri":"([^"]*)")/g.exec(T)){r1=RegExp.$1;r2=RegExp.$2;if(/^https?:/.exec(r2)){t[i++]='['+(i)+']:<a href='+r2+'>'+r2+'<\/a>';}}with(window.open().document){for(i=0;t[i];i++)write(t[i]+'<br>');close();}})();

(2)打开一个空白的firefox选项卡。

(3)将你的firefox json文件拖到空白标签中,这应该打开json文件。

(4)转到您在步骤1中创建的书签。

(5)您应该拥有所有书签的“可点击网址”列表。

答案 1 :(得分:0)

如果您使用Excel,则可能很容易对分割

的列进行文本处理 <{1>} "。鉴于格式(字段的顺序)始终相同,您应该在最后一列附近的某处使用URL。

答案 2 :(得分:0)

我没有测试过这个。

注意:验证/更正以下所有文件路径以匹配您的系统。

@Echo Off
Rem FFExportBookmarks.bat

SetLocal EnableDelayedExpansion
Set JSONFile="%APPDATA%\Mozilla\Firefox\Profiles\xyz42pdq.default\bookmarkbackups\Bookmarks.json"
Set FavOut="%USERPROFILE%\My Documents\FFBookmarks.txt"
Set JSONTemp="%Temp%\JSONTemp.txt"
Echo.> %JSONTemp%
Set JSONTemp1="%Temp%\JSONTemp1.txt"
Echo.> %JSONTemp1%

For /f "UseBackQ Delims=" %%N In ('Type %JSONFile%') Do (
  Set JSONInput=%%N
Rem Filter double " and other delimiters
  Set JSONInput=!JSONInput:"=!
  Set JSONInput=!JSONInput: =!
  Set JSONInput=!JSONInput:^,= !
  Set JSONInput=!JSONInput:[= !
  Set JSONInput=!JSONInput:]= !
  Set JSONInput=!JSONInput:{= !
  Set JSONInput=!JSONInput:}= !

  For %%K In (!JSONInput!) Do For /f "Tokens=1,2 Delims=:" %%X In ("%%K") Do (
    If /i "%%X"=="uri" Echo %%Y >> %FavOut%
  )
)

Start "" %FavOut%

它不是很快,但它很脏!

相关问题