C# 获取Google Chrome的书签
其实这个很简单,就是读取一个在用户目录里面的一个Bookmarks文件就好了。
先建立几个实体类
public class GoogleChrome_bookMark_meta_info
{
public string last_visited_desktop { get; set; }
} public class GoogleChrome_BookMark_children
{
public string date_added { get; set; }
public string id { get; set; }
public GoogleChrome_bookMark_meta_info meta_info { get; set; }
public string name { get; set; }
public string type { get; set; }
public string url { get; set; }
public List<GoogleChrome_BookMark_children> children { get; set; } } public class GoogleChrome_BookMark_bookmark_bar_other_synced
{
public string date_added { get; set; }
public string date_modified { get; set; }
public string id { get; set; }
public string name { get; set; }
public string type { get; set; }
public List<GoogleChrome_BookMark_children> children { get; set; }
} public class GoogleChrome_BookMark_roots
{
public GoogleChrome_BookMark_bookmark_bar_other_synced bookmark_bar { get; set; }
public GoogleChrome_BookMark_bookmark_bar_other_synced other { get; set; }
public GoogleChrome_BookMark_bookmark_bar_other_synced synced { get; set; }
} public class GoogleChrome_BookMarkAllModel
{
public string checksum { get; set; }
public GoogleChrome_BookMark_roots roots { get; set;}
public string version { get; set; }
}
具体实现
static void Main(string[] args)
{
///建几个Bookmarks 的实体类(Model)用来承载数据
//获取由指定枚举标识的系统特殊文件夹的路径 ,, 其实就是读取用户目录下的Google Chrome 的Bookmarks 文件。
string ChromeDatePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)+@"\Google\Chrome\User Data\Default";
string ChromeBookMarksPath = ChromeDatePath + @"\Bookmarks";
if (File.Exists(ChromeBookMarksPath))
{
Console.WriteLine("Chrome浏览器书签文件存在");
}
else
Console.WriteLine("未找到Chrome浏览器书签");
Console.WriteLine(ChromeBookMarksPath);
StreamReader sr = new StreamReader(ChromeBookMarksPath);
string str = "";
while (!sr.EndOfStream)
{
str += sr.ReadLine();
}
sr.Close();
string str2 = System.Text.RegularExpressions.Regex.Replace(str, "\\s*|\t|\r|\n", ""); //去空格、回车符
Console.WriteLine(str2);
//转为JSON格式
var obj = JsonConvert.DeserializeObject<GoogleChrome_BookMarkAllModel>(str2);
if (obj.roots.bookmark_bar != null)
ShowChildren(, obj.roots.bookmark_bar.children);
Console.ReadKey(); } /// <summary>
/// 输出书签节点
/// </summary>
/// <param name="index">其实是没有用的,为了好看</param>
/// <param name="children">书签集合</param>
public static void ShowChildren(int index, List<GoogleChrome_BookMark_children> children)
{
foreach (var l in children)
{
Console.WriteLine("");
Console.WriteLine(GetTreeStr(index) + "书签ID:" + l.id);
Console.WriteLine(GetTreeStr(index) + "书签名称:" + l.name);
Console.WriteLine(GetTreeStr(index) + "书签类型:" + l.type);
if (l.type == "folder")
{
Console.WriteLine(GetTreeStr(index) + l.name + "是文件夹,文件夹下标签数量为:" + l.children.Where(w => w.type == "url").Count()
+ "文件夹数量为:" + l.children.Where(w => w.type == "folder").Count());
Console.WriteLine(GetTreeStr(index) + l.name + "目录下内容");
}
else
Console.WriteLine(GetTreeStr(index) + "书签url:" + l.url);
}
} /// <summary>
/// 为了好看
/// </summary>
/// <param name="index">随便什么int数</param>
/// <returns></returns>
public static string GetTreeStr(int index)
{
string str = "";
for (int i = ; i < index; i++)
{
str += "...";
}
str += "L";
return str;
}
C# 获取Google Chrome的书签的更多相关文章
- google chrome 浏览器书签丢失问题
在一次新打开标签页时,电脑卡死,强制重启后打开google chrome 浏览器,发现历史什么的都在,但书签栏全部丢失了 找到 系统盘:\Users\用户名\AppData\Local\Google\ ...
- 一个获取google chrome扩展crx文件信息的PHP操作类
此类中实现了从crx文件获取扩展的Appid.获取manifest.json文件内容.将crx文件转换为一般zip文件 代码如下: <?php class CrxParserException ...
- [C#]Google Chrome 书签导出并生成 MHTML 文件
目的 因为某些原因需要将存放在 Google Chrome 内的书签导出到本地,所幸 Google Chrome 提供了导出书签的功能. 分析 首先在 Google Chrome 浏览器当中输入 ch ...
- Google Chrome 书签导出并生成 MHTML 文件
目的 因为某些原因需要将存放在 Google Chrome 内的书签导出到本地,所幸 Google Chrome 提供了导出书签的功能. 分析 首先在 Google Chrome 浏览器当中输入 ch ...
- google chrome 删除重复的书签 about sync
之前 由于 谷歌 同步的不智能,且不询问用户同步方法和细节,导致我的书签包括了大量重复的书签,想去除重复的书签. 由于谷歌书签文件 存储在:C:\Documents and Settings\Admi ...
- 15个你不知道的杀手级Google Chrome功能
之前写过一篇我为什么使用Google Chrome浏览器,算是在使用了一段时间的Google Chrome后的一点粗浅认识,最近读到一篇文章15 Killer Google Chrome Featur ...
- 浅谈Google Chrome浏览器(理论篇)
注解:各位读者,经博客园工作人员反馈,hosts涉及违规问题,我暂时屏蔽了最新hosts,若已经获取最新hosts的朋友们,注意保密,不要外传.给大家带来麻烦,对此非常抱歉!!! 开篇概述 1.详解g ...
- 详解google Chrome浏览器(理论篇)
注解:各位读者,经博客园工作人员反馈,hosts涉及违规问题,我暂时屏蔽了最新hosts,若已经获取最新hosts的朋友们,注意保密,不要外传.给大家带来麻烦,对此非常抱歉!!! 开篇概述 1.详解g ...
- Google Chrome 浏览器的备用(离线)安装程序
Google Chrome 浏览器的备用(离线)安装程序(适用于 Windows) 如果您在使用 http://www.google.com/chrome 上的标准安装程序下载 Chrome 浏览器时 ...
随机推荐
- cogs 421. HH的项链
421. HH的项链 http://218.28.19.228/cogs/problem/problem.php?pid=421 ★★★ 输入文件:diff.in 输出文件:diff.out ...
- 洛谷P4239 【模板】多项式求逆(加强版)(多项式求逆)
传送门 咱用的是拆系数\(FFT\)因为咱真的不会三模数\(NTT\)-- 简单来说就是把每一次多项式乘法都改成拆系数\(FFT\)就行了 如果您还不会多项式求逆的左转->这里 顺带一提,因为求 ...
- ESQL 查询数据报 参数类型“Edm.Decimal”和“Edm.Double”不兼容
ESQL 查询数据报 参数类型“Edm.Decimal”和“Edm.Double”不兼容 System.Data.Entity.Core.Objects.ObjectQuery<TEntity& ...
- Struts2拦截器再认识
拦截器(Interceptor)是 Struts 2 的核心组成部分. Struts2 很多功能都是构建在拦截器基础之上的,例如文件的上传和下载.国际化.数据类型转换和数据校验等等. Struts2 ...
- java课后思考问题(八)
1.请阅读并运行AboutException.java示例,然后通过后面的几页PPT了解Java中实现异常处理的基础知识. (1)import javax.swing.*; class AboutEx ...
- js和jq中常见的各种位置距离之offsetLeft/clientLeft/scrollLeft (一)
offsetLeft offsetTop offsetWidth offsetHeight offsetLeft:元素的边框的外边缘距离与已定位的父容器(offsetparent)的左边距离(不包括元 ...
- mysql issue:
####0 https://yq.aliyun.com/ziliao/53466 首先,很荣幸你找到了这篇文章... 如果你忘记了mysql的密码不妨试试以下这个方法. 1.打开my.cnf 代码如 ...
- reaver 破解wifi
1. 无线网卡设置为监控模式 airmon-ng start wlan0 2. 获取附近路由信息 airodump-ng wlan0mon 3. 使用reaver破解wifi reaver -i wl ...
- NIO学习之Channel
一.Channel基础 通道是一个对象,通过它可以读取和写入数据,Channel就是通向什么的道路,为数据的流向提供渠道: 在传统IO中,我们要读取一个文件中的内容使用Inputstream,该str ...
- zuul忽略表达式
如果有error过滤器,会进入error