本篇内容介绍了“怎么使用python提取chrome浏览器的历史记录及收藏夹”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
1.打开 chrome浏览器,输入 chrome://version,进入浏览器版本信息页面 2.复制页面下图,划线地址
上面我的chrome浏览器的缓存路径是:
C:\Users\Administrator\AppData\Local\Google\Chrome\User Data\Default
浏览器的收藏夹的数据,记录在Bookmarks文件里面
Bookmark文件的内容格式是json
解析代码为
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
历史数据,存储在下面的History文件里面,内容格式是sqlite的数据库文件,可以直接使用sqlite3来解析,当然也可以使用DB Browser for SQLite来图形化界面显示History sqlite数据文件。
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
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
“怎么使用python提取chrome浏览器的历史记录及收藏夹”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。