2014-09-02 39 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()