适用于Google Chrome的Internet历史记录脚本

问题描述 投票:4回答:5

我不是在寻找一个“最好”或最有效的脚本来做到这一点。但我想知道是否有一个脚本可以将Google历史记录拉上一天的时间,例如Google Chrome并将其记录到txt文件中。我更喜欢它是在Python还是MATLAB中。

如果你们使用谷歌浏览器的本地存储浏览器历史数据,使用这些语言中的一种语言有不同的方法,我也会全神贯注。

如果有人能帮助我,我会非常感激!

python matlab google-chrome
5个回答
4
投票

根据我的理解,它似乎很容易完成。我不知道这是不是你想要的。 Chrome的互联网历史记录存储在特定路径中。以Win7为例,它存储在win7:C:\Users\[username]\AppData\Local\Google\Chrome\User Data\Default\History

在Python中:

f = open('C:\Users\[username]\AppData\Local\Google\Chrome\User Data\Default\History', 'rb')
data = f.read()
f.close()
f = open('your_expected_file_path', 'w')
f.write(repr(data))
f.close()

2
投票

建立在m170897017上的说法:

该文件是一个sqlite3数据库,因此使用其内容的repr()将不会做任何有意义的事情。

您需要打开sqlite数据库并对其运行SQL以获取数据。在python中使用stdlib中的sqlite3库来执行此操作。

这是一个相关的SuperUser问题,它显示了一些用于获取URL和时间戳的SQL:https://superuser.com/a/694283


0
投票

躲避sqlite3 / sqlite,我正在使用Google Chrome扩展程序“导出历史记录”,将所有内容导出为CSV文件,然后将该CSV文件加载到MATLAB中的单元格中。

Export History

我的代码原来是:

file_o = ['history.csv'];
fid = fopen(file_o, 'rt');
fmt = [repmat('%s', 1, 6) '%*[^\n]'];
C = textscan(fid,fmt,'Delimiter',',','CollectOutput',true);
C_unpacked = C{:}; 
C_urls = C_unpacked(1:4199, 5);

0
投票

这是另一个:

import csv, sqlite3, os
from datetime import datetime, timedelta

connection = sqlite3.connect(os.getenv("APPDATA") + "\..\Local\Google\Chrome\User Data\Default\history")
connection.text_factory = str
cur = connection.cursor()
output_file = open('chrome_history.csv', 'wb')
csv_writer = csv.writer(output_file)
headers = ('URL', 'Title', 'Visit Count', 'Date (GMT)')
csv_writer.writerow(headers)
epoch = datetime(1601, 1, 1)
for row in (cur.execute('select url, title, visit_count, last_visit_time from urls')):
    row = list(row)
    url_time = epoch + timedelta(microseconds=row[3])
    row[3] = url_time
    csv_writer.writerow(row)

0
投票

这不是你想要的。但是,通过使用它,您可以根据自己的喜好操作数据库表

import os
import sqlite3

def Find_path():
    User_profile = os.environ.get("USERPROFILE")
    History_path = User_profile + r"\\AppData\Local\Google\Chrome\User Data\Default\History" #Usually this is where the chrome history file is located, change it if you need to.
    return History_path

def Main():
    data_base = Find_path()            
    con = sqlite3.connect(data_base) #Connect to the database
    c = con.cursor()
    c.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name") #Change this to your prefered query
    print(c.fetchall())
if __name__ == '__main__':
    Main()
© www.soinside.com 2019 - 2024. All rights reserved.