ExportEdgeUrl.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. '''
  2. Created on 2016年10月23日
  3. 链接:https://www.zhihu.com/question/33742288/answer/127179880
  4. @author: liuyuqi
  5. #!/usr/bin/env python3
  6. # -*- coding: utf-8 -*-
  7. # 这个工具可以用来把edge的收藏夹导出为ie那种目录结构的url文件,导出后的文件大家可以替换到ie的收藏夹下,然后通过其他浏览器的导入功能把ie收藏夹导入到别的浏览器
  8. '''
  9. import json
  10. import os
  11. import re
  12. favoritesPath = r'C:\Users\dell\AppData\Local\Packages\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\RoamingState' # edge收藏夹json文件存放位置
  13. urlPath = r'D:\BackUp\\' # 存放导出的url文件的位置
  14. # 从字符串获取合法的文件名
  15. def getFileName(str):
  16. rstr = r'[\/\\\:\*\?\"\<\>\|]'
  17. fileName = re.sub(rstr, '_', str)
  18. return fileName
  19. # 从edge浏览器收藏夹的json文件中获取每一个网址的目录及url
  20. def getFavoritePath(fileName):
  21. favoritePath = None
  22. if os.path.splitext(fileName)[1] == '.json':
  23. with open(fileName, 'r', encoding='utf-8') as f:
  24. s = json.load(f)
  25. if not s['IsFolder']:
  26. favoritePath = [urlPath, s['Title'], s['URL']]
  27. ParentId = s['ParentId']
  28. mybool = True
  29. # while mybool:
  30. # with open(favoritesPath + '\\' + ParentId + '.json', 'r', encoding='utf-8') as f1:
  31. # s1 = json.load(f1)
  32. # favoritePath[0] = s1['Title'] + '\\' + favoritePath[0]
  33. # ParentId = s1['ParentId']
  34. # mybool = False
  35. # if s1['Title'] == '_Favorites_Bar_':
  36. # mybool = False
  37. # favoritePath[0] = urlPath + '\\' + favoritePath[0]
  38. return favoritePath
  39. # 创建url快捷方式
  40. def createUrl(createPath, url):
  41. f = open(createPath, 'w', encoding='utf-8')
  42. f.write('[InternetShortcut]\nURL=' + url)
  43. # 开始执行=========================================
  44. os.chdir(favoritesPath)
  45. for filename in os.listdir():
  46. favoritePath = getFavoritePath(filename)
  47. if favoritePath:
  48. # if os.path.isdir(favoritePath[0]):
  49. # pass
  50. # else:
  51. # os.makedirs(favoritePath[0])
  52. favoritePath[1] = getFileName(favoritePath[1])
  53. print(favoritePath[0] + favoritePath[1] + '.url', favoritePath[2], filename)
  54. createUrl(favoritePath[0] + favoritePath[1] + '.url', favoritePath[2])