2014-09-02 60 views
4

我不是在寻找一个“最好”或最有效的脚本来做到这一点。但是我想知道是否存在一段脚本,可以让谷歌浏览器在一天内拉出互联网历史记录并将其记录到一个txt文件中。我宁愿如果它在Python或MATLAB。谷歌浏览器的互联网历史脚本

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

如果有人可以帮忙,我会非常感谢!

回答

3

从我的理解来看,似乎很容易做到。我不知道这是你想要的。 来自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库来执行此操作。

这里有一个相关的超级用户问题,表明一些SQL用于获取URL和时间戳:https://superuser.com/a/694283

+0

这是一个好的下载? [pysqlite 2.6.3](https://pypi.python.org/pypi/pysqlite)? – 2014-09-02 02:44:55

+0

是的,应该工作。但是,sqlite也是内置在python的标准库中的。在python解释器中试试这个:“import sqlite3”。如果可行,你不需要下载一个图书馆。请参阅sqlite3文档:https://docs.python.org/3/library/sqlite3.html – 2014-09-02 03:09:24

0

回避的sqlite3/SQLite的,我使用的是谷歌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

这wan't正是您要寻找的,但通过使用您可以操纵您喜欢的数据库表格

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()