python解析Chrome瀏覽器歷史瀏覽記錄和收藏夾數(shù)據(jù)
前言
常使用chrome瀏覽器作為自己的默認(rèn)瀏覽器,也喜歡使用瀏覽器來收藏自己的喜歡的有用的鏈接,自己也做了一個(gè)記錄筆記的小腳本,想擴(kuò)展收錄chrome瀏覽器收藏夾的內(nèi)容,,下面,,使用python提取chrome瀏覽器的歷史記錄,以及收藏夾。
(一)查詢chrome數(shù)據(jù)緩存地址
1.打開 chrome瀏覽器,輸入 chrome://version,進(jìn)入瀏覽器版本信息頁面 2.復(fù)制頁面下圖,劃線地址

(二)提取收藏夾數(shù)據(jù)
1.文件路徑
上面我的chrome瀏覽器的緩存路徑是:
C:\Users\Administrator\AppData\Local\Google\Chrome\User Data\Default
瀏覽器的收藏夾的數(shù)據(jù),記錄在Bookmarks文件里面
Bookmark文件的內(nèi)容格式是json

2.解析代碼
解析代碼為
import os
import json
#chrome data path
path = "C:/Users/Administrator/AppData/Local/Google/Chrome/User Data/Default"
#chrome browser bookmark
class BookMark:
def __init__(self,chromePath=path):
#chromepath
self.chromePath = chromePath
#parse bookmarks
with open(os.path.join(path,'Bookmarks'),encoding='utf-8') as f:
bookmarks = json.loads(f.read())
self.bookmarks = bookmarks
#folders
self.folders = self.get_folders()
def get_folders(self):
#folders
names = [
(i,self.bookmarks['roots'][i]['name'])
for i in self.bookmarks['roots']
]
return names
def get_folder_data(self,folder=0):
return self.bookmarks['roots'][self.folders[folder][0]]['children']
def set_chrome_path(self,chromePath):
self.chromePath = chromePath
def refresh(self):
'update chrome data from chrome path'
#parse bookmarks
with open(os.path.join(path,'Bookmarks'),encoding='utf-8') as f:
bookmarks = json.loads(f.read())
self.bookmarks = bookmarks
(三)查看瀏覽歷史數(shù)據(jù)
1.文件路徑
歷史數(shù)據(jù),存儲(chǔ)在下面的History文件里面,內(nèi)容格式是sqlite的數(shù)據(jù)庫文件,可以直接使用sqlite3來解析,當(dāng)然也可以使用DB Browser for SQLite來圖形化界面顯示History sqlite數(shù)據(jù)文件。

2.解析代碼
import os
import sqlite3
#chrome data path
path = "C:/Users/Administrator/AppData/Local/Google/Chrome/User Data/Default"
#History
class History:
def __init__(self,chromePath=path):
self.chromePath = chromePath
def connect(self):
self.conn = sqlite3.connect(os.path.join(self.chromePath,"History"))
self.cousor = self.conn.cursor()
def close(self):
self.conn.close()
def get_history(self):
cursor = self.conn.execute("SELECT id,url,title,visit_count from urls")
rows = []
for _id,url,title,visit_count in cursor:
row = {}
row['id'] = _id
row['url'] = url
row['title'] = title
row['visit_count'] = visit_count
rows.append(row)
return rows
(四)完整代碼&測(cè)試代碼
import os
import sqlite3
#chrome data path
path = "C:/Users/Administrator/AppData/Local/Google/Chrome/User Data/Default"
#History
class History:
def __init__(self,chromePath=path):
self.chromePath = chromePath
def connect(self):
self.conn = sqlite3.connect(os.path.join(self.chromePath,"History"))
self.cousor = self.conn.cursor()
def close(self):
self.conn.close()
def get_history(self):
cursor = self.conn.execute("SELECT id,url,title,visit_count from urls")
rows = []
for _id,url,title,visit_count in cursor:
row = {}
row['id'] = _id
row['url'] = url
row['title'] = title
row['visit_count'] = visit_count
rows.append(row)
return rows
總結(jié)
到此這篇關(guān)于python解析Chrome瀏覽器歷史瀏覽記錄和收藏夾數(shù)據(jù)的文章就介紹到這了,更多相關(guān)python解析Chrome瀏覽器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
pycharm無法安裝第三方庫的問題及解決方法以scrapy為例(圖解)
這篇文章主要介紹了pycharm無法安裝第三方庫的解決辦法以scrapy為例,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-05-05
Python正則表達(dá)re模塊之findall()函數(shù)詳解
在python中,通過內(nèi)嵌集成re模塊可以直接調(diào)用來實(shí)現(xiàn)正則匹配,其中re.findall()函數(shù)可以遍歷匹配,可以獲取字符串中所有匹配的字符串,返回一個(gè)列表,這篇文章主要給大家介紹了關(guān)于Python正則表達(dá)re模塊之findall()函數(shù)的相關(guān)資料,需要的朋友可以參考下2022-07-07
Pycharm 2to3配置,python2轉(zhuǎn)python3方式
這篇文章主要介紹了Pycharm 2to3配置,python2轉(zhuǎn)python3方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12
Python編寫一個(gè)驗(yàn)證碼圖片數(shù)據(jù)標(biāo)注GUI程序附源碼
這篇文章主要介紹了Python編寫一個(gè)驗(yàn)證碼圖片數(shù)據(jù)標(biāo)注GUI程序,本文給大家附上小編精心整理的源碼,需要的朋友可以參考下2019-12-12
人工智能學(xué)習(xí)Pytorch進(jìn)階操作教程
這篇文章主要為大家介紹了人工智能學(xué)習(xí)Pytorch進(jìn)階操作的詳解教程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步2021-11-11

