如何在本地计算机上以编程方式访问 Google Chrome 浏览器历史记录

发布于 2024-08-27 09:10:11 字数 337 浏览 8 评论 0原文

我想编写一个简单的程序来显示我在一段时间内的互联网活动(我访问了哪个网站,访问了多少次等等)。我主要使用谷歌Chrome浏览器。我发现 Chrome 在此位置存储浏览器历史记录(如果我错了,请纠正我)

C:\Documents and Settings\<username>\Local Settings\Application Data\Google\Chrome\User Data\Default

如何打开历史记录文件?它们没有任何文件扩展名。我无法使用记事本、SQLite 浏览器打开。如何以编程方式访问这些数据?我想知道它是什么格式以及如何使用 C# 等编程语言读取它。

I want to write a simple program which shows my internet activity over a period of time (which site I visited, how many times and so on). I mostly use Google Chrome browser. I found out Chrome stores browser history at this location (please correct me if I'm wrong)

C:\Documents and Settings\<username>\Local Settings\Application Data\Google\Chrome\User Data\Default

How can I open the history files? They don't have any file extension. I could not open using notepad, SQLite browser. How do I access this data programmatically? I want to know which file format it is and how to read it using a programming language like C#.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

莫言歌 2024-09-03 09:10:12

为了查看 sqlite 数据库(这就是 Chromium 历史索引),我更喜欢 sqlitebrowser。它是免费的,可在 Windows、Mac 和 Linux 上运行。我一直以来的最爱。

For viewing sqlite databases (which is what the Chromium history index is), I've preferred sqlitebrowser. It's free and works on Windows, Mac, and Linux. An all-time fave for me.

花落人断肠 2024-09-03 09:10:12

由于原始发帖人要求一个简单的程序,所以就在这里。该程序改编自java工作区网站(如代码所示)。您需要更改 getConnection () 的参数以指向历史文件在您的计算机上所在的位置。该程序在我的Linux 2.6.39环境上编译并运行:

/**
 Adapted from http://www.javaworkspace.com/connectdatabase/connectSQLite.do
 Date: 09/25/2012

 Download sqlite-jdbc-<>.jar from http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC, and
 compile: javac GetChromiumHistory.java
 run:     java -classpath ".:sqlite-jdbc-3.7.2.jar" GetChromiumHistory
*/

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * @author www.javaworkspace.com
 * 
 */
public class GetChromiumHistory
{
    public static void main (String[] args) 
    {

    Connection connection = null;
    ResultSet resultSet = null;
    Statement statement = null;

    try 
        {
        Class.forName ("org.sqlite.JDBC");
        connection = DriverManager
            .getConnection ("jdbc:sqlite:/home/username/.config/chromium/Default/History");
        statement = connection.createStatement ();
        resultSet = statement
            .executeQuery ("SELECT * FROM urls where visit_count > 100");

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

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

    finally 
        {
        try 
            {
            resultSet.close ();
            statement.close ();
            connection.close ();
            } 

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

Since the original poster asked for a simple program, here it is. The program was adapted from the java workspace website (as credited in the code). You will need to change the argument for getConnection () to point to where the history files reside on your machine. The program compiles and runs on my Linux 2.6.39 environment:

/**
 Adapted from http://www.javaworkspace.com/connectdatabase/connectSQLite.do
 Date: 09/25/2012

 Download sqlite-jdbc-<>.jar from http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC, and
 compile: javac GetChromiumHistory.java
 run:     java -classpath ".:sqlite-jdbc-3.7.2.jar" GetChromiumHistory
*/

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * @author www.javaworkspace.com
 * 
 */
public class GetChromiumHistory
{
    public static void main (String[] args) 
    {

    Connection connection = null;
    ResultSet resultSet = null;
    Statement statement = null;

    try 
        {
        Class.forName ("org.sqlite.JDBC");
        connection = DriverManager
            .getConnection ("jdbc:sqlite:/home/username/.config/chromium/Default/History");
        statement = connection.createStatement ();
        resultSet = statement
            .executeQuery ("SELECT * FROM urls where visit_count > 100");

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

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

    finally 
        {
        try 
            {
            resultSet.close ();
            statement.close ();
            connection.close ();
            } 

        catch (Exception e) 
            {
            e.printStackTrace ();
            }
        }
    }
}
浅黛梨妆こ 2024-09-03 09:10:12

有一个名为 Hindsight (https://github.com/obsidianforensics/hindsight) 的开源程序可以分析Chrome 中的浏览历史记录。虽然该程序相当大且复杂,但它使用 SQL 查询访问各种 Chrome SQLite 文件,这些文件可以在 SQLite 浏览器或不同的程序中独立提取和使用。

Chrome v30+ 历史数据库的一个示例是:

SELECT urls.id, urls.url, urls.title, urls.visit_count, urls.typed_count, urls.last_visit_time, urls.hidden, urls.favicon_id, visits.visit_time, visits.from_visit, visits.visit_duration, visits.transition, visit_source.source
FROM urls JOIN visits ON urls.id = visits.url
LEFT JOIN visit_source ON visits.id = visit_source.id

不同的 Chrome 数据库以及不同版本的 Chrome 有更多的 SQL 查询。

There is an open source program called Hindsight (https://github.com/obsidianforensics/hindsight) that analyzes browsing history in Chrome. While the program is rather large and complicated, it access the various Chrome SQLite files using SQL queries, which can pull out and use independently, either in a SQLite browser or a different program.

An example of one for the Chrome v30+ History database is:

SELECT urls.id, urls.url, urls.title, urls.visit_count, urls.typed_count, urls.last_visit_time, urls.hidden, urls.favicon_id, visits.visit_time, visits.from_visit, visits.visit_duration, visits.transition, visit_source.source
FROM urls JOIN visits ON urls.id = visits.url
LEFT JOIN visit_source ON visits.id = visit_source.id

There are many more SQL queries for different Chrome databases, as well as different versions of Chrome.

暖心男生 2024-09-03 09:10:12

我知道 Safari 使用 Binary PLists 作为其历史记录(以及 SQLite用于其缓存)。 Chrome 有可能也在做同样的事情吗?

I know Safari uses Binary PLists for its history (and SQLite for its cache). Is it possible that Chrome is doing the same?

掐死时间 2024-09-03 09:10:11

它只是一个 SQlite 3 数据库,我能够成功打开它(当然你无法打开正在运行的浏览器的锁定数据库)。

It is just a SQlite 3 database, I was able to open it successfully (though of course you can't open a locked database of a running browser).

半山落雨半山空 2024-09-03 09:10:11

这是我创建的一个类,用于从 Google Chrome 读取浏览数据。我从此处获得的大部分代码,但是我对其进行了一些调整以添加对 Google Chrome 的支持。您可能还想从 此处下载 SQLite for .Net 并添加对 System.Data.Sqlite 的引用。

class GoogleChrome
{
    public List<URL> URLs = new List<URL>();
    public IEnumerable<URL> GetHistory()
    {
        // Get Current Users App Data
        string documentsFolder = Environment.GetFolderPath
        (Environment.SpecialFolder.ApplicationData);
        string[] tempstr = documentsFolder.Split('\\');
        string tempstr1 = "";
        documentsFolder += "\\Google\\Chrome\\User Data\\Default";
        if (tempstr[tempstr.Length - 1] != "Local")
        {
            for (int i = 0; i < tempstr.Length - 1; i++)
            {
                tempstr1 += tempstr[i] + "\\";
            }
            documentsFolder =  tempstr1 + "Local\\Google\\Chrome\\User Data\\Default";
        }


        // Check if directory exists
        if (Directory.Exists(documentsFolder))
        {
            return ExtractUserHistory(documentsFolder);

        }
        return null;
    }


    IEnumerable<URL> ExtractUserHistory(string folder)
    {
        // Get User history info
        DataTable historyDT = ExtractFromTable("urls", folder);

        // Get visit Time/Data info
        DataTable visitsDT = ExtractFromTable("visits",
        folder);

        // Loop each history entry
        foreach (DataRow row in historyDT.Rows)
        {

                // Obtain URL and Title strings
                string url = row["url"].ToString();
                string title = row["title"].ToString();

                // Create new Entry
                URL u = new URL(url.Replace('\'', ' '),
                title.Replace('\'', ' '),
                "Google Chrome");

                // Add entry to list
                URLs.Add(u);
        }
        // Clear URL History
        DeleteFromTable("urls", folder);
        DeleteFromTable("visits", folder);

        return URLs;
    }
    void DeleteFromTable(string table, string folder)
    {
        SQLiteConnection sql_con;
        SQLiteCommand sql_cmd;

        // FireFox database file
        string dbPath = folder + "\\History";

        // If file exists
        if (File.Exists(dbPath))
        {
            // Data connection
            sql_con = new SQLiteConnection("Data Source=" + dbPath +
            ";Version=3;New=False;Compress=True;");

            // Open the Conn
            sql_con.Open();

            // Delete Query
            string CommandText = "delete from " + table;

            // Create command
            sql_cmd = new SQLiteCommand(CommandText, sql_con);

            sql_cmd.ExecuteNonQuery();

            // Clean up
            sql_con.Close();
        }
    }

    DataTable ExtractFromTable(string table, string folder)
    {
        SQLiteConnection sql_con;
        SQLiteCommand sql_cmd;
        SQLiteDataAdapter DB;
        DataTable DT = new DataTable();

        // FireFox database file
        string dbPath = folder + "\\History";

        // If file exists
        if (File.Exists(dbPath))
        {
            // Data connection
            sql_con = new SQLiteConnection("Data Source=" + dbPath +
            ";Version=3;New=False;Compress=True;");

            // Open the Connection
            sql_con.Open();
            sql_cmd = sql_con.CreateCommand();

            // Select Query
            string CommandText = "select * from " + table;

            // Populate Data Table
            DB = new SQLiteDataAdapter(CommandText, sql_con);
            DB.Fill(DT);

            // Clean up
            sql_con.Close();
        }
        return DT;
    }
}

URL 的类:

class URL
{
    string url;
    string title;
    string browser;
    public URL(string url, string title, string browser)
    {
        this.url = url;
        this.title = title;
        this.browser = browser;
    }

    public string getData()
    {
        return browser + " - " + title + " - " + url;
    }
}

它对我来说就像一个魅力。希望有帮助

Here is a class I created to read browsing data from Google chrome. Most of the code I got from here but I tweaked it abit to add support for Google Chrome. You probably also want to download the SQLite for .Net from here and add the references to System.Data.Sqlite.

class GoogleChrome
{
    public List<URL> URLs = new List<URL>();
    public IEnumerable<URL> GetHistory()
    {
        // Get Current Users App Data
        string documentsFolder = Environment.GetFolderPath
        (Environment.SpecialFolder.ApplicationData);
        string[] tempstr = documentsFolder.Split('\\');
        string tempstr1 = "";
        documentsFolder += "\\Google\\Chrome\\User Data\\Default";
        if (tempstr[tempstr.Length - 1] != "Local")
        {
            for (int i = 0; i < tempstr.Length - 1; i++)
            {
                tempstr1 += tempstr[i] + "\\";
            }
            documentsFolder =  tempstr1 + "Local\\Google\\Chrome\\User Data\\Default";
        }


        // Check if directory exists
        if (Directory.Exists(documentsFolder))
        {
            return ExtractUserHistory(documentsFolder);

        }
        return null;
    }


    IEnumerable<URL> ExtractUserHistory(string folder)
    {
        // Get User history info
        DataTable historyDT = ExtractFromTable("urls", folder);

        // Get visit Time/Data info
        DataTable visitsDT = ExtractFromTable("visits",
        folder);

        // Loop each history entry
        foreach (DataRow row in historyDT.Rows)
        {

                // Obtain URL and Title strings
                string url = row["url"].ToString();
                string title = row["title"].ToString();

                // Create new Entry
                URL u = new URL(url.Replace('\'', ' '),
                title.Replace('\'', ' '),
                "Google Chrome");

                // Add entry to list
                URLs.Add(u);
        }
        // Clear URL History
        DeleteFromTable("urls", folder);
        DeleteFromTable("visits", folder);

        return URLs;
    }
    void DeleteFromTable(string table, string folder)
    {
        SQLiteConnection sql_con;
        SQLiteCommand sql_cmd;

        // FireFox database file
        string dbPath = folder + "\\History";

        // If file exists
        if (File.Exists(dbPath))
        {
            // Data connection
            sql_con = new SQLiteConnection("Data Source=" + dbPath +
            ";Version=3;New=False;Compress=True;");

            // Open the Conn
            sql_con.Open();

            // Delete Query
            string CommandText = "delete from " + table;

            // Create command
            sql_cmd = new SQLiteCommand(CommandText, sql_con);

            sql_cmd.ExecuteNonQuery();

            // Clean up
            sql_con.Close();
        }
    }

    DataTable ExtractFromTable(string table, string folder)
    {
        SQLiteConnection sql_con;
        SQLiteCommand sql_cmd;
        SQLiteDataAdapter DB;
        DataTable DT = new DataTable();

        // FireFox database file
        string dbPath = folder + "\\History";

        // If file exists
        if (File.Exists(dbPath))
        {
            // Data connection
            sql_con = new SQLiteConnection("Data Source=" + dbPath +
            ";Version=3;New=False;Compress=True;");

            // Open the Connection
            sql_con.Open();
            sql_cmd = sql_con.CreateCommand();

            // Select Query
            string CommandText = "select * from " + table;

            // Populate Data Table
            DB = new SQLiteDataAdapter(CommandText, sql_con);
            DB.Fill(DT);

            // Clean up
            sql_con.Close();
        }
        return DT;
    }
}

The class for the URL:

class URL
{
    string url;
    string title;
    string browser;
    public URL(string url, string title, string browser)
    {
        this.url = url;
        this.title = title;
        this.browser = browser;
    }

    public string getData()
    {
        return browser + " - " + title + " - " + url;
    }
}

It worked like a charm for me. Hope it helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文