zoukankan      html  css  js  c++  java
  • 读取firefox浏览器历史记录(nim学习系列)

    读取firefox浏览器历史记录(nim学习系列)

    读取firefox历史记录

    读取firefox浏览器历史记录并保存到CSV文件(需要sqlite3_64.dll或者sqlite3_32.dll)。
    编译:

    nim c -d:release --opt:size --cpu:amd64 firefoxHistory.nim

    nim c -d:release --opt:size --cpu:i386 firefoxHistory.nim

    源代码

    #[
    Author: StudyCat
    Blog: https://www.cnblogs.com/studycat
    Github: https://github.com/StudyCat404/myNimExamples
    License: BSD 3-Clause
    ]#
    
    import db_sqlite
    import osproc
    import os
    import strutils
    import streams
    import times
    
    let time = cpuTime()
        
    proc findDBFiles(command: string): seq[string] =
        echo command
        var cmdArgs: array[3,string]
        var outp: string
        
        cmdArgs[0] = "/Q"
        cmdArgs[1] = "/C"
        cmdArgs[2] = command
        let shell = os.getEnv("COMSPEC")
        outp = osproc.execProcess(shell, args=cmdArgs, options={poStdErrToStdOut,poUsePath})
        var line = ""
        var strm = newStringStream(outp)
        if not isNil(strm):    
            while strm.readLine(line):
                if line.len() > 0:
                    result.add(line)
      
    proc firefoxHistory(dbFilePath: string) =
        var record: string
        var f: File
        f = open("firefoxHistory.csv", fmAppend)
        
        if fileExists(dbFilePath):
            let db = open(dbFilePath, "", "", "")
            try:
                for row in db.fastRows(sql"select moz_places.title, moz_places.url, datetime(moz_places.last_visit_date / 1000000, 'unixepoch') from moz_places"):
                    record = join(row, ",")
                    f.writeLine(record)
            except:
                stderr.writeLine(getCurrentExceptionMsg())
            finally:
                db.close()
        f.close()   
    
    when isMainModule:
        when defined windows:
            for path in findDBFiles("dir '%appdata%/../Local/Google/Chrome/User Data/Default/History' /s /b"):
                firefoxHistory(path)  
        
            echo "Time taken: ", cpuTime() - time, "s"    
    
  • 相关阅读:
    7-1 抓老鼠啊~亏了还是赚了?
    7-1 币值转换
    7-1 打印沙漏
    打印沙漏
    第十周作业
    第九周作业
    第八周作业
    第七周作业
    7-1 判断上三角矩阵 (15 分)
    第二次实验过程
  • 原文地址:https://www.cnblogs.com/StudyCat/p/14290349.html
Copyright © 2011-2022 走看看