使用Python解析Chrome浏览器书签的示例


Posted in Python onNovember 13, 2020

Chrome 浏览器的书签如果可以导出,并转换为我们需要的格式时,我们就可以编写各种插件来配合书签的使用。

答案显然是可以的,接下来我们以 Python 为例写一个遍历打印书签的例子

书签地址

先来说下获取书签的方法

Chrome 浏览器的书签存放位置在各个平台的区别

  • Mac
~/Library/Application Support/Google/Chrome/Default/Bookmarks
  • Linux
~/.config/google-chrome/Default/Bookmarks
  • Windows
%LOCALAPPDATA%"\Google\Chrome\User Data\Default\Bookmarks"

书签结构

书签内容为 JSON 格式,结构如下

{
  "checksum":"b196f618a9166d56dc6c98cfe9a98d45",
  "roots":{
    "bookmark_bar":{
      "children":[
        {
          "date_added":"13246172853099058",
          "guid":"83431411-157f-45f8-a9a4-d9af26c71bce",
          "id":"1944",
          "name":"blog local 温欣爸比的博客",
          "type":"url",
          "url":"http://localhost:4000/"
        },
        {
          "children":[
            {
              "date_added":"13246172853099058",
              "guid":"83431411-157f-45f8-a9a4-d9af26c71bce",
              "id":"1944",
              "name":"blog local 温欣爸比的博客",
              "type":"url",
              "url":"http://localhost:4000/"
            }
          ],
          "date_added":"13246172844427649",
          "date_modified":"13246172865895702",
          "guid":"6aa4ecce-a220-4689-9239-7df10965748b",
          "id":"1943",
          "name":"Blog",
          "type":"folder"
        }
      ],
      "date_added":"13242060909278534",
      "date_modified":"13246172853099058",
      "guid":"00000000-0000-4000-a000-000000000002",
      "id":"1",
      "name":"书签栏",
      "type":"folder"
    },
    "other":{
      "children":[

      ],
      "date_added":"13242060909278616",
      "date_modified":"0",
      "guid":"00000000-0000-4000-a000-000000000003",
      "id":"2",
      "name":"其他书签",
      "type":"folder"
    },
    "synced":{
      "children":[

      ],
      "date_added":"13242060909278621",
      "date_modified":"0",
      "guid":"00000000-0000-4000-a000-000000000004",
      "id":"3",
      "name":"移动设备书签",
      "type":"folder"
    }
  },
  "sync_metadata":"",
  "version":1
}

清晰了这个结构在写代码就很简单了,以书签栏为例,只需要将 data['roots']['bookmark_bar']['children'] 进行循环遍历即可,代码详情可见 demo

完整demo

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author: wxnacy(wxnacy@gmail.com)
# Description: 打印不换行进度条
# 预览 https://raw.githubusercontent.com/wxnacy/image/master/blog/python_progress.gif

import time


def get_progress(progress, total):
  '''获取进度条'''
  progress_ratio = progress / total
  progress_len = 20
  progress_num = int(progress_ratio * 20)
  pro_text = '[{:-<20s}] {:.2f}% {} / {}'.format(
    '=' * progress_num, progress_ratio * 100, progress, total)
  return pro_text

def print_progress(total):
  '''模拟打印进度条'''
  progress = 0
  step = 30
  while progress < total:
    time.sleep(1)
    b = progress
    e = b + step
    progress += step
    end = '\r'
    if progress >= total:
      end = '\n'
      progress = total
    print(get_progress(progress, total), end = end)

if __name__ == "__main__":
  print_progress(100)

以上就是使用Python解析Chrome浏览器书签的示例的详细内容,更多关于Python解析Chrome浏览器书签的资料请关注三水点靠木其它相关文章!

Python 相关文章推荐
简单介绍使用Python解析并修改XML文档的方法
Oct 15 Python
python动态网页批量爬取
Feb 14 Python
python中返回矩阵的行列方法
Apr 04 Python
Python实现的基于优先等级分配糖果问题算法示例
Apr 25 Python
django开发post接口简单案例,获取参数值的方法
Dec 11 Python
Python实现的各种常见分布算法示例
Dec 13 Python
使用urllib库的urlretrieve()方法下载网络文件到本地的方法
Dec 19 Python
一篇文章弄懂Python中所有数组数据类型
Jun 23 Python
通过Turtle库在Python中绘制一个鼠年福鼠
Feb 03 Python
Python连接Oracle之环境配置、实例代码及报错解决方法详解
Feb 11 Python
PyCharm 无法 import pandas 程序卡住的解决方式
Mar 09 Python
Python3交互式shell ipython3安装及使用详解
Jul 11 Python
python 实现围棋游戏(纯tkinter gui)
Nov 13 #Python
python3从网络摄像机解析mjpeg http流的示例
Nov 13 #Python
python+flask编写一个简单的登录接口
Nov 13 #Python
jupyter notebook快速入门及使用详解
Nov 13 #Python
Python中pass的作用与使用教程
Nov 13 #Python
python入门教程之基本算术运算符
Nov 13 #Python
python“静态”变量、实例变量与本地变量的声明示例
Nov 13 #Python
You might like
在php中使用sockets:从新闻组中获取文章
2006/10/09 PHP
smarty的保留变量问题
2008/10/23 PHP
PHPExcel读取EXCEL中的图片并保存到本地的方法
2015/02/14 PHP
php生成带logo二维码方法小结
2016/04/08 PHP
通过chrome浏览器控制台(Console)进行PHP Debug的方法
2016/10/19 PHP
Laravel框架实现修改登录和注册接口数据返回格式的方法
2018/08/17 PHP
兼容Mozilla必须知道的知识。
2007/01/09 Javascript
javascript 数组的定义和数组的长度
2016/06/07 Javascript
jQuery多选框选择数量限制方法
2017/02/08 Javascript
Vue中之nextTick函数源码分析详解
2017/10/17 Javascript
每天学点Vue源码之vm.$mount挂载函数
2019/03/11 Javascript
Nodejs环境实现socket通信过程解析
2020/07/03 NodeJs
vue 解决data中定义图片相对路径页面不显示的问题
2020/08/13 Javascript
详解Vue的组件中data选项为什么必须是函数
2020/08/17 Javascript
python SSH模块登录,远程机执行shell命令实例解析
2018/01/12 Python
python给微信好友定时推送消息的示例
2019/02/20 Python
django mysql数据库及图片上传接口详解
2019/07/18 Python
django 环境变量配置过程详解
2019/08/06 Python
Python搭建代理IP池实现获取IP的方法
2019/10/27 Python
python3 实现调用串口功能
2019/12/26 Python
TensorFlow学习之分布式的TensorFlow运行环境
2020/02/05 Python
40行Python代码实现天气预报和每日鸡汤推送功能
2020/02/27 Python
完美解决python针对hdfs上传和下载的问题
2020/06/05 Python
Kneipp克奈圃美国官网:德国百年精油配方的传承
2018/02/07 全球购物
印度服装购物网站:Limeroad
2018/09/26 全球购物
Lacoste(法国鳄鱼)加拿大官网:以标志性的POLO衫而闻名
2019/05/15 全球购物
美国亚马逊旗下男装网站:East Dane(支持中文)
2019/09/25 全球购物
Ellos瑞典官网:北欧地区时尚、美容和住宅领域领先的电子商务网站
2019/11/21 全球购物
String和StringBuffer的区别
2015/08/13 面试题
单位委托书范本
2014/04/04 职场文书
常务副总经理任命书
2014/06/05 职场文书
群众路线剖析材料(四风)
2014/11/05 职场文书
出国签证在职证明范本
2014/11/24 职场文书
会计求职自荐信范文
2015/03/04 职场文书
篮球赛新闻稿
2015/07/17 职场文书
Golang数据类型和相互转换
2022/04/12 Golang