Programmatically acess Google chrome history

心不动则不痛 提交于 2019-11-28 11:34:30

You need to download the appropriate assembly from the SqLite downloads page

Once you add a reference to the SQLite assembly, its very similar to standard ADO.net

All the user history is stored in the History database located at the path in the connection string below

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

In Windows form application with Datagridview tool - button click event

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)
        {
        }
    }

Reference source

Here i have copied the History file to Application startup path in order to avoid SQLite error "database is locked".

Tarun Kakkar

Used below code getting "Windows/x86_64" as a result

   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 ();
    } 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!