编程访问谷歌chrome历史
本文关键字:历史 chrome 谷歌 访问 编程 | 更新日期: 2023-09-27 18:18:33
我想索引所有的用户操作和网站在谷歌浏览器。我知道谷歌chrome索引所有的数据在sqlite数据库。我如何在我自己的应用程序编程访问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());
}
在Windows窗体应用程序中使用Datagridview工具-按钮单击事件
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)
{
}
}
引用源
这里我已经将历史文件复制到应用程序启动路径,以避免SQLite错误"database is locked"
下面使用的代码得到"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 ();
}
这段代码可能会对您有所帮助:
//Use sqlite for read chrome history
using System;
using System.IO;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Data.SQLite;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
GetChromehistory();
Console.WriteLine();
}
public void GetChromehistory()
{
//Connection string
string path = @"'Google'Chrome'User Data'Default'History";
string chromehistorypath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + path;
if (File.Exists(chromehistorypath))
{
SQLiteConnection connection = new SQLiteConnection("Data Source=" + chromehistorypath + ";Version=3;New=False;Compress=True;");
connection.Open();
DataSet dataSet = new DataSet();
SQLiteDataAdapter adapter = new SQLiteDataAdapter("select * from urls order by last_visit_time desc", connection);
connection.Close();
adapter.Fill(dataSet);
var allHistoryItems = new List<ChromeHistoryItem>();
if (dataSet != null && dataSet.Tables.Count > 0 & dataSet.Tables[0] != null)
{
DataTable dt = dataSet.Tables[0];
foreach (DataRow historyRow in dt.Rows)
{
ChromeHistoryItem historyItem = new ChromeHistoryItem()
{
URL = Convert.ToString(historyRow["url"]),
Title = Convert.ToString(historyRow["title"])
};
// Chrome stores time elapsed since Jan 1, 1601 (UTC format) in microseconds
long utcMicroSeconds = Convert.ToInt64(historyRow["last_visit_time"]);
// Windows file time UTC is in nanoseconds, so multiplying by 10
DateTime gmtTime = DateTime.FromFileTimeUtc(10 * utcMicroSeconds);
// Converting to local time
DateTime localTime = TimeZoneInfo.ConvertTimeFromUtc(gmtTime, TimeZoneInfo.Local);
historyItem.VisitedTime = localTime;
allHistoryItems.Add(historyItem);
}
}
}
}
}
public class ChromeHistoryItem
{
public string URL { get; set; }
public string Title { get; set; }
public DateTime VisitedTime { get; set; }
}