1。关闭Chrome浏览器
2。备份书签,我的书签在
C:UsersAdministratorAppDataLocalGoogleChromeUser DataDefaultBookmarks
2。运行以下python程序。
import os
import json
import requests
import time
import shutil
from datetime import datetime
from concurrent.futures import ThreadPoolExecutor, as_completed
# --- 用户配置 ---
BOOKMARKS_PATH = None
TIMEOUT = 10
MAX_WORKERS = 20
# --- 脚本核心代码 ---
def find_bookmarks_file():
# ... (这部分代码无需改变,保持原样)
"""尝试在常见的路径中自动查找书签文件"""
paths_to_check = {
'win': os.path.expanduser('~') + '/AppData/Local/Google/Chrome/User Data/Default/Bookmarks',
'mac': os.path.expanduser('~') + '/Library/Application Support/Google/Chrome/Default/Bookmarks',
'linux': os.path.expanduser('~') + '/.config/google-chrome/Default/Bookmarks'
}
if BOOKMARKS_PATH and os.path.exists(BOOKMARKS_PATH):
print(f"✅ 使用手动配置的书签文件路径: {BOOKMARKS_PATH}")
return BOOKMARKS_PATH
# 检查常见的Profile路径
for i in range(1, 6): # 检查Default和Profile 1到5
profile = 'Default' if i == 0 else f'Profile {i}'
win_path_profile = os.path.expanduser('~') + f'/AppData/Local/Google/Chrome/User Data/{profile}/Bookmarks'
if os.path.exists(win_path_profile):
print(f"✅ 自动找到书签文件: {win_path_profile}")
return win_path_profile
for os_type, path in paths_to_check.items():
if os.path.exists(path):
print(f"✅ 自动找到书签文件: {path}")
return path
return None
# ======================================================================
# ↓↓↓ 这里是关键的修改 ↓↓↓
# ======================================================================
def get_bookmarks_urls(node):
"""【已修正】递归地从书签树中提取所有书签URL和名称"""
bookmarks = []
# 如果当前节点是URL,则直接添加
if isinstance(node, dict) and node.get('type') == 'url':
# 确保URL存在且不为空
if node.get('url'):
bookmarks.append({'name': node.get('name', 'N/A'), 'url': node.get('url')})
# 如果当前节点包含子节点,则递归遍历
if isinstance(node, dict) and 'children' in node:
for child in node['children']:
bookmarks.extend(get_bookmarks_urls(child))
return bookmarks
def extract_all_bookmarks(roots_dict):
"""【新增】遍历roots字典下所有根文件夹(如bookmark_bar, other, synced)"""
all_bookmarks = []
if isinstance(roots_dict, dict):
for root_name, root_node in roots_dict.items():
all_bookmarks.extend(get_bookmarks_urls(root_node))
return all_bookmarks
# ======================================================================
# ↑↑↑ 关键修改结束 ↑↑↑
# ======================================================================
total_count = len(all_bookmarks)
if total_count == 0: