2011-12-22 124 views
3

我想索引谷歌瀏覽器中的所有用戶操作和網站。我明白google chrome索引sqlLite數據庫中的所有數據。我如何通過編程訪問Chrome網上應用歷史在我自己的應用程序以編程方式訪問谷歌瀏覽器歷史記錄

+0

重複的http://stackoverflow.com/questions/2562092/how-to-access-google-chrome-browser-history-programmatically-on-local-machine。 – ziesemer

+0

當你說VS 2008時,我假設你的意思是.net 3.5。VS是一個IDE,而不是一個框架。 – CodesInChaos

+0

可能會問爲什麼?數據庫被鎖定 – mesutpiskin

回答

7

您需要從SqLite downloads page

下載相應的組件一旦你添加一個參考SQLite的組件,它非常類似於標準的ADO.net

所有用戶歷史記錄存儲在位於路徑的連接字符串在下面

SQLiteConnection conn = new SQLiteConnection 
    (@"Data Source=C:\Users\YourUserName\AppData\Local\Google\Chrome\User Data\Default\History"); 
conn.Open(); 
SQLiteCommand cmd = new SQLiteCommand(); 
cmd.Connection = conn; 
// cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;"; 
// Use the above query to get all the table names 
cmd.CommandText = "Select * From urls"; 
SQLiteDataReader dr = cmd.ExecuteReader(); 
while (dr.Read()) 
{ 
Console.WriteLine(dr[1].ToString()); 
} 
+0

數據庫被鎖定異常被拋出 – 2017-03-26 18:13:12

+0

同一個「數據庫被鎖定」 –

+0

也許數據庫被鎖定,因爲Chrome的活動實例正在使用它,嘗試將該文件複製到另一個位置,然後閱讀它。 – dlopezgonzalez

0

歷史數據庫中使用下面的代碼獲得的「Windows/x86_64的」結果

try 
    { 
     Class.forName ("org.sqlite.JDBC"); 
     connection = DriverManager.getConnection ("jdbc:sqlite:/C:/Users/tarun.kakkar/AppData/Local/Google/Chrome/User Data/Default/History"); 

     statement = connection.createStatement(); 
     resultSet = statement.executeQuery ("SELECT * FROM urls"); 

     while (resultSet.next()) 
     { 
      System.out.println ("URL [" + resultSet.getString ("url") + "]" + ", visit count [" + resultSet.getString ("visit_count") + "]"); 
     } 
    } 

    catch (Exception e) 
    { 
     e.printStackTrace(); 
    } 
1

與DataGridView的工具Windows窗體應用程序 - 按鈕單擊事件

private void button1_Click(object sender, EventArgs e) 
    { 
     string google = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Google\Chrome\User Data\Default\History"; 
     string fileName = DateTime.Now.Ticks.ToString(); 
     File.Copy(google, Application.StartupPath + "\\" + fileName); 
     using (SQLiteConnection con = new SQLiteConnection("DataSource = " + Application.StartupPath + "\\" + fileName + ";Versio=3;New=False;Compress=True;")) 
     { 
      con.Open(); 
      //SQLiteDataAdapter da = new SQLiteDataAdapter("select url,title,visit_count,last_visit_time from urls order by last_visit_time desc", con); 
      SQLiteDataAdapter da = new SQLiteDataAdapter("select * from urls order by last_visit_time desc", con); 
      DataSet ds = new DataSet(); 
      da.Fill(ds); 
      dataGridView1.DataSource = ds.Tables[0]; 
      con.Close(); 
     } 
     try // File already open error is skipped 
     { 
      if (File.Exists(Application.StartupPath + "\\" + fileName)) 
      File.Delete(Application.StartupPath + "\\" + fileName); 
     } 
     catch (Exception) 
     { 
     } 
    } 

參考source

在這裏,我已經複製歷史文件應用程序啓動路徑,以避免SQLite的錯誤「數據庫被鎖住了」。