How to access Google Chrome browser history programmatically on local machine

后端 未结 6 685
無奈伤痛
無奈伤痛 2020-12-07 15:44

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.

6条回答
  •  一向
    一向 (楼主)
    2020-12-07 16:39

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

提交回复
热议问题