我不是在寻找最好的"或最有效的脚本来做到这一点。但我想知道是否存在一个脚本,可以将Google历史记录从一段时间拉到谷歌浏览器并将其记录到txt文件中。如果是Python或MATLAB,我更喜欢。
如果你们使用谷歌Chrome浏览器的本地存储浏览器历史数据,使用这些语言中的一种语言有不同的方法,我也会全力以赴。
如果有人能帮助我,我会非常感激!
答案 0 :(得分: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()
答案 1 :(得分:2)
以m170897017所说的为基础:
该文件是一个sqlite3数据库,因此取其内容的repr()
将无意义。
您需要打开sqlite数据库并对其运行SQL以获取数据。在python中使用stdlib中的sqlite3库来执行此操作。
以下是一个相关的超级用户问题,其中显示了一些用于获取网址和时间戳的SQL:https://superuser.com/a/694283
答案 2 :(得分:0)
Dodged sqlite3 / sqlite,我正在使用Google Chrome扩展程序“导出历史记录”,将所有内容导出为CSV文件,然后将该CSV文件加载到MATLAB中的单元格中。
我的代码原来是:
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);
答案 3 :(得分: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)
答案 4 :(得分: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()