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浏览器书签的资料请关注其它相关文章!

广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。