如果还没有重装/卸载浏览器,那么可能数据还在本地,可以用下面的python脚本导出单个html文件,然后使用edge的导入html文件的功能将分组作为文件夹导入浏览器里,实测是可行的:
import sqlite3
import json
import os
import shutil
# Edge 默认配置文件的集锦数据库路径 (如使用其他配置,将 Default 替换为 Profile 1 等)
DB_PATH = os.path.expandvars(r"%LocalAppData%\Microsoft\Edge\User Data\Default\Collections\collectionsSQLite")
TEMP_DB_PATH = "collectionsSQLite_temp.db"
OUTPUT_HTML = "Edge_Collections_Bookmarks.html"
def export_to_html():
if not os.path.exists(DB_PATH):
print(f"[!] 错误: 未找到数据库文件 -> {DB_PATH}")
print("请检查路径。如果存在多个浏览器配置文件,可能位于 Profile 1 或 Profile 2 文件夹下。")
return
# 复制到当前目录,避免 Edge 进程占用导致数据库被锁定
try:
shutil.copy2(DB_PATH, TEMP_DB_PATH)
except IOError as e:
print(f"[!] 复制数据库文件失败: {e}")
return
con = sqlite3.connect(TEMP_DB_PATH)
cur = con.cursor()
# 关联 collections 和 items 表
query = """
SELECT c.title as folder, i.title as title, i.source as data
FROM collections as c, items as i, collections_items_relationship as r
WHERE r.item_id == i.id and r.parent_id == c.id
"""
try:
cur.execute(query)
rows = cur.fetchall()
except sqlite3.Error as e:
print(f"[!] 数据库读取错误: {e}")
return
finally:
con.close()
if os.path.exists(TEMP_DB_PATH):
os.remove(TEMP_DB_PATH)
collections = {}
for folder_name, title, data_blob in rows:
try:
# 数据储存于包含页面元数据的 JSON BLOB 中
data_json = json.loads(data_blob.decode('utf8'))
url = data_json.get("url", "")
if url:
if folder_name not in collections:
collections[folder_name] = []
collections[folder_name].append({"title": title, "url": url})
except Exception:
continue
# 构建 Netscape 标准书签 HTML 结构
html_lines = [
"",
"",
"
"
Edge Collections Export
","
{folder}
")html_lines.append("
- {item_title}")
html_lines.append("
"
]
for folder, items in collections.items():
html_lines.append(f"
")
for item in items:
item_title = item['title'].replace("&", "&").replace("<", "<").replace(">", ">")
html_lines.append(f"
")
html_lines.append("
")
with open(OUTPUT_HTML, "w", encoding="utf-8") as f:
f.write("\n".join(html_lines))
print(f"[*] 导出成功!文件已生成在当前目录: {OUTPUT_HTML}")
print("[*] 该 HTML 文件可直接导入到主流浏览器的书签/收藏夹中。")
if __name__ == "__main__":
export_to_html()