以编程方式访问Google Chrome历史记录

我想索引谷歌浏览器中的所有用户操作和网站。 据我所知,谷歌chrome索引sqlLite数据库中的所有数据。 我如何以编程方式访问我自己的应用程序中的chrome Web历史记录

您需要从SqLite下载页面下载相应的程序集

添加对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()); } 

在带有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) { } } 

参考来源

在这里,我已将History文件复制到Application启动路径,以避免SQLite错误“数据库被锁定”。

在下面的代码中使用“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 (); }