You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过编程从本地Chrome浏览器配置文件中提取完整浏览历史数据

Chrome浏览历史文件结构说明

Chrome全版本的浏览历史均为SQLite3格式数据库文件,无加密、非纯文本,你自定义的配置目录下,历史文件默认路径为:g:\profiles\chrome\<user_dir>\Default\History(无后缀名)。
Chrome使用的时间戳为1601年1月1日起累计的微秒数,和常用的1970年起点Unix时间戳不同,提取时需要做转换。

各语言实现示例

所有语言实现前都建议先把History文件复制到临时路径再操作,避免Chrome运行时锁定原文件导致读取失败。

Python 实现(无需额外安装依赖,sqlite3为标准库)

import sqlite3
import os
import datetime

# 替换为你的History文件路径
origin_history_path = r"g:\profiles\chrome\<user_dir>\Default\History"
temp_history_path = "./temp_chrome_history"

# 复制原文件到临时路径,避免文件锁
with open(origin_history_path, "rb") as src, open(temp_history_path, "wb") as dst:
    dst.write(src.read())

conn = sqlite3.connect(temp_history_path)
cursor = conn.cursor()
# 核心查询语句:urls表存储所有访问过的URL和对应最后访问时间
cursor.execute("SELECT url, last_visit_time FROM urls ORDER BY last_visit_time DESC")
all_records = cursor.fetchall()

# Chrome时间戳转本地时间
def convert_chrome_time(chrome_ts):
    if chrome_ts == 0:
        return ""
    unix_ts = (chrome_ts / 1000000) - 11644473600
    return datetime.datetime.fromtimestamp(unix_ts).strftime("%Y-%m-%d %H:%M:%S")

for url, ts in all_records:
    local_time = convert_chrome_time(ts)
    print(f"URL:{url},最后访问时间:{local_time}")

cursor.close()
conn.close()
os.remove(temp_history_path)

该代码兼容最新版Chrome,所有Chromium内核浏览器(Edge、Brave等)的历史提取逻辑完全一致。

Java 实现

需要引入sqlite-jdbc依赖,Maven坐标如下:

<dependency>
    <groupId>org.xerial</groupId>
    <artifactId>sqlite-jdbc</artifactId>
    <version>3.45.0.0</version>
</dependency>

核心逻辑和Python完全相同:复制文件后连接SQLite数据库,执行相同的查询语句,按照同样的规则转换时间戳即可。

Rust 实现

需要引入rusqlite和chrono依赖,Cargo.toml配置如下:

[dependencies]
rusqlite = "0.30.0"
chrono = { version = "0.4.31", features = ["local"] }

核心逻辑同上,复制文件后执行SQL查询,将Chrome微秒时间戳转换为本地时间输出即可。

注意事项
  • 如果你创建了多套profile,历史文件会存放在Profile 1、Profile 2这类目录下,而非Default目录,根据实际使用的profile调整路径即可
  • 如需获取每次访问的详细记录、跳转来源、访问时长等数据,可以查询visits表关联urls表获取对应信息

内容的提问来源于stack exchange,提问作者user10664542

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 21:09:03