## 一键分析你的上网行为, 看看你平时上网都在干嘛?
## Chrome浏览器历史记录文件可视化
### 简介
**想看看你最近一年都在干嘛?看看你平时上网是在摸鱼还是认真工作?想写年度汇报总结,但是苦于没有数据?现在,它来了。**
这是一个能让你了解自己的浏览历史的Chrome浏览历史记录分析程序,**他适用于Chrome浏览器或者以Chromium为内核的浏览器。目前国内大部分浏览器均是以Chromium为内核的浏览器,所以基本上都可以使用。但是不支持以下浏览器:IE浏览器、Firefox浏览器、Safari浏览器。**
在该页面中你将可以查看有关自己在过去的时间里所访问浏览的域名、URL以及忙碌天数的前十排名以及相关的数据图表。
<br />
<br />
### 部分截图
![](demo.gif)
<br />
<br />
### 代码思路
#### 1. 目录结构
首先,我们先看一下整体目录结构
```bash
Code
├─ app_callback.py 回调函数,实现后台功能
├─ app_configuration.py web服务器配置
├─ app_layout.py web前端页面配置
├─ app_plot.py web图表绘制
├─ app.py web服务器的启动
├─ assets web所需的一些静态资源文件
│ ├─ css web前端元素布局文件
│ │ ├─ custum-styles_phyloapp.css
│ │ └─ stylesheet.css
│ ├─ image web前端logo图标
│ │ ├─ GitHub-Mark-Light.png
│ └─ static web前端帮助页面
│ │ ├─ help.html
│ │ └─ help.md
├─ history_data.py 解析chrome历史记录文件
└─ requirement.txt 程序所需依赖库
```
- app_callback.py
该程序基于python,使用dash web轻量级框架进行部署。`app_callback.py`主要用于回调,可以理解为实现后台功能。
- app_configuration.py
顾名思义,对web服务器的一些配置操作。
- app_layout..py
web前端页面配置,包含html, css元素。
- app_plot.py
这个主要是为实现一些web前端的图表数据。
- app.py
web服务器的启动。
- assets
静态资源目录,用于存储一些我们所需要的静态资源数据。
- history_data.py
通过连接sqlite数据库,并解析Chrome历史记录文件。
- requirement.txt
运行本程序所需要的依赖库。
<br />
#### 2. 解析历史记录文件数据
与解析历史记录文件数据有关的文件为`history_data.py`文件。我们一一分析。
```python
# 查询数据库内容
def query_sqlite_db(history_db, query):
# 查询sqlite数据库
# 注意,History是一个文件,没有后缀名。它不是一个目录。
conn = sqlite3.connect(history_db)
cursor = conn.cursor()
# 使用sqlite查看软件,可清晰看到表visits的字段url=表urls的字段id
# 连接表urls和visits,并获取指定数据
select_statement = query
# 执行数据库查询语句
cursor.execute(select_statement)
# 获取数据,数据格式为元组(tuple)
results = cursor.fetchall()
# 关闭
cursor.close()
conn.close()
return results
```
**该函数的代码流程为:**
1. 连接sqlite数据库,执行查询语句,返回查询结构,最终关闭数据库连接。
```python
# 获取排序后的历史数据
def get_history_data(history_file_path):
try:
# 获取数据库内容
# 数据格式为元组(tuple)
select_statement = "SELECT urls.id, urls.url, urls.title, urls.last_visit_time, urls.visit_count, visits.visit_time, visits.from_visit, visits.transition, visits.visit_duration FROM urls, visits WHERE urls.id = visits.url;"
result = query_sqlite_db(history_file_path, select_statement)
# 将结果按第1个元素进行排序
# sort和sorted内建函数会优先排序第1个元素,然后再排序第2个元素,依此类推
result_sort = sorted(result, key=lambda x: (x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8]))
# 返回排序后的数据
return result_sort
except:
# print('读取出错!')
return 'error'
```
**该函数的代码流程为:**
1. 设置数据库查询语句`select_statement`,调用`query_sqlite_db()`函数,获取解析后的历史记录文件数据。并对返回后的历史记录数据文件按照不同元素规则进行排序。至此,经过排序的解析后的历史记录数据文件获取成功。
<br />
#### 3. web服务器基本配置
与web服务器基本配置有关的文件为`app_configuration.py`和`app.py`文件。包括设置web服务器的端口号,访问权限,静态资源目录等。
<br />
#### 4. 前端页面部署
与前端部署有关的文件为`app_layout.py`和`app_plot.py`以及`assets`目录。
前端布局主要包括以下几个元素:
- 上传历史记录文件组件
- 绘制页面访问次数组件
- 绘制页面访问停留总时间排名组件
- 每日页面访问次数散点图组件
- 某日不同时刻访问次数散点图组件
- 访问次数最多的10个URL组件
- 搜索关键词排名组件
- 搜索引擎使用情况组件
在`app_layout.py`中,**这些组件的配置大多一样,和平常的html, css配置一样,所以我们仅仅以配置`页面访问次数排名组件`为例子。**
```python
# 页面访问次数排名
html.Div(
style={'margin-bottom':'150px'},
children=[
html.Div(
style={'border-top-style':'solid','border-bottom-style':'solid'},
className='row',
children=[
html.Span(
children='页面访问次数排名, ',
style={'font-weight': 'bold', 'color':'red'}
),
html.Span(
children='显示个数:',
),
dcc.Input(
id='input_website_count_rank',
type='text',
value=10,
style={'margin-top':'10px', 'margin-bottom':'10px'}
),
]
),
html.Div(
style={'position': 'relative', 'margin': '0 auto', 'width': '100%', 'padding-bottom': '50%', },
children=[
dcc.Loading(
children=[
dcc.Graph(
id='graph_website_count_rank',
style={'position': 'absolute', 'width': '100%', 'height': '100%', 'top': '0',
'left': '0', 'bottom': '0', 'right': '0'},
config={'displayModeBar': False},
),
],
type='dot',
style={'position': 'absolute', 'top': '50%', 'left': '50%', 'transform': 'translate(-50%,-50%)'}
),
],
)
]
)
```
可以看到,虽然是python编写的,但是只要具备前端经验的人,都可以轻而易举地在此基础上新增或者删除一些元素,所以我们就不详细讲如何使用html和css了。
在`app_plot.py`中,主要是以绘制图表相关的。使用的是`plotly`库,这是一个用于具有web交互的画图组件库。
这里以绘制`页面访问频率排名 柱状图`为例子,讲讲如何使用`plotly`库进行绘制。
```python
# 绘制 页面访问频率排名 柱状图
def plot_bar_website_count_rank(value, history_data):
# 频率字典
dict_data = {}
# 对历史记录文件进行遍历
for data in history_data:
url = data[1]
# 简化url
key = url_simplification(url)
if (key in dict_data.keys()):
dict_data[key] += 1
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
一些非常有趣的python爬虫例子,对新手比较友好 (106个子文件)
font-awesome.min.css 35KB
skeleton.min.css 7KB
css.css 2KB
loading_screen.css 1KB
custom_styles.css 246B
fund_data.csv 520KB
chromedriver_win32_74.0.3729.6.exe 8.19MB
example.gif 1.56MB
example.gif 1.56MB
example.gif 1.31MB
example.gif 880KB
example2.gif 510KB
demo.gif 407KB
.gitignore 233B
.gitignore 71B
.gitignore 71B
help.html 19KB
config.ini 2KB
page3.jpeg 300KB
md5.js 9KB
getCSRFToken.js 547B
LICENSE 1KB
README.MD 18KB
README.md 16KB
README.MD 13KB
README.md 12KB
README.md 12KB
README.MD 9KB
README.md 8KB
README.MD 6KB
README.md 2KB
help.md 1KB
README.MD 920B
README.MD 908B
README.MD 858B
page1.png 1.62MB
page2.png 1.21MB
example10.png 341KB
example9.png 334KB
example_rating.png 333KB
location.png 270KB
page5.png 257KB
page6.png 219KB
example1.png 218KB
page4.png 206KB
example1.png 193KB
demo2.png 188KB
example2.png 183KB
history.png 158KB
example2.png 155KB
example2.png 145KB
example8.png 134KB
example3.png 96KB
example4.png 87KB
demo1.png 87KB
example2.png 78KB
example1.png 76KB
example1.png 69KB
GitHub-Mark-Light.png 49KB
example4.png 48KB
example7.png 42KB
example4.png 34KB
example5.png 31KB
example3.png 30KB
example2.png 23KB
example6.png 23KB
example3.png 10KB
chinese_flag.png 910B
ui_object.py 37KB
qq_bot.py 33KB
generate_wx_data.py 24KB
app_layout.py 17KB
static_data.py 16KB
main.py 13KB
app_plot.py 12KB
say_to_lady.py 10KB
get_movie_data.py 9KB
main.py 9KB
tmall_crawler.py 9KB
app_callback.py 8KB
pyqt_gui.py 6KB
wereader.py 6KB
taobao_buy_crawler.py 6KB
main.py 5KB
main.py 4KB
taobao_login.py 3KB
history_data.py 2KB
tkinter_gui.py 2KB
decrypt.py 2KB
excel_func.py 2KB
app.py 1KB
url_request.py 1KB
app_configuration.py 499B
main.py 124B
sentence_good_morning.txt 2KB
sentence_good_lunch.txt 2KB
sentence_good_dinner.txt 2KB
sentence_good_dream.txt 2KB
requirement.txt 117B
requirement.txt 77B
共 106 条
- 1
- 2
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6832
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功