解析 mozilla firefox json 文件的快速但肮脏的方法

发布于 2024-10-03 06:08:20 字数 1186 浏览 4 评论 0原文

我想从 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 之类的东西并为其编写脚本之前进行替换。

I want to scrape all of the url's out of my .json bookmark backup that firefox creates and output a .txt file.

Here's a sample of one of the objects located in the file:

{"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/"}

These objects are comma-separated and should all contain at least one member that contains a string whose value is the url of the bookmark.

Here's a sample of what the .txt file would have in it:

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

Ideally, I'm interested in seeing if this can be pulled off using any scripting tools available within a generic Windows XP "environment".

If Windows can't cut it, what would be the quickest & easiest solution to this?

Is there a website or program that can do pattern matching or regex to parse the file do search & replace before I go install something like Active Perl or Strawberry Perl and write a script for it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

药祭#氼 2024-10-10 06:08:20

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

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) 您应该有一个包含所有书签的“可点击 URL”列表。

Another way I found is the method at the following site:

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

Basically you do the following:

(1) Create a firefox bookmark with the following as the location:

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) Open a blank firefox tab.

(3) drag your firefox json file into the blank tab, this should open the json file.

(4) goto your bookmark you created in step 1.

(5) you should have a list of "clickable urls" for all your bookmarks.

薔薇婲 2024-10-10 06:08:20

如果您有 Excel,则可能很容易将文本拆分为列

on "。鉴于格式(字段顺序)始终相同,您应该将 URL 放在最后一列附近。

If you have Excel, it's probably easy to do a text to columns split

on ". Given the format (order of fields) is always the same, you should have the URLs somewhere near the last column.

枯寂 2024-10-10 06:08:20

我没有测试过这个。

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

@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%

速度不是很快,但是很脏!

I haven't tested this.

NOTE: Verify/correct all below file paths to match your system.

@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%

It wasn't very quick, but it's plenty dirty!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文