Help us understand the problem. What is going on with this article?

pythonでChrome内のsqliteから閲覧履歴を抽出する!

Chromeの閲覧履歴って、Historyというsqliteファイルにまとまっているようです。

私のWindows10/64のChromeは、'C:\Users(ユーザ名)\AppData\Local\Google\Chrome\User Data\Default\History'というフォルダにHistoryが格納されていました。

次のコードで閲覧履歴を抽出してファイルに保存できます。History(sqlite)内のurlsとvisitsという2つのテーブルにクエリをかけるプログラムです。コード内の「(ユーザ名)」の部分は、適宜変更してください。

注意点ですが、Chrome起動中はHistory(sqlite)ファイルがロックされているため、次のプログラムはchromeが起動していないときに動かしてみてください。

##### IMPORT
import sqlite3
from contextlib import closing
from datetime import datetime

##### CONST
db = r'C:\Users\(ユーザ名)\AppData\Local\Google\Chrome\User Data\Default\History'
filePath = './result.txt'

##### IMPLEMENTATION
with closing(sqlite3.connect(db)) as conn:
    c = conn.cursor()
    select_sql = "select visits.id, urls.url, urls.title, visits.visit_time,visits.from_visit from visits inner join urls on visits.url = urls.id"
    with open(filePath, mode='a', encoding='utf-8') as f:
        for row in c.execute(select_sql):
            timestamp = datetime.fromtimestamp(row[3]/1000000-11644473600)
            strLine =str(row[0])+','+row[1] + ', ' + row[2] + ', ' + str(timestamp) + ', ' + str(row[4])+'\n'
            print(strLine)
            f.write(strLine)
        f.close()



Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away