每个人都有自己的知识体系。
Toggle navigation
Home
随笔
C#/.Net
树莓派 / Raspberry
皓月汉化组
Beego
Golang
OxideMod
apache
haproxy
windows
Java
Objective-C
日语/罗马音歌词/日语常识
MongoDB
python
电学
公告
Minecraft服务器-公告
NanoPi
C4D (CINEMA 4D)
生活
推流/m3u8/rtmp/rtsp
Unity3d
ffmpeg
数据结构
区块链
tarui
UnityForPSVita
About Me
Archives
Tags
C# 获取并解析Google Chrome浏览器书签文件
2017-09-17 18:11:10
454
0
0
akiragatsu
using Newtonsoft.Json; #region Chrome书签结构实体类 public class GoogleChrome_BookMarkALLModel { public string checksum { get; set; } public GoogleChrome_BookMark_roots roots { get; set; } public string version { 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_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_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_meta_info { public string last_visited_desktop { get; set; } } #endregion static void Main(string[] args) { 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("____________________ Json原文如下 ______________________"); Console.WriteLine(str2); var obj = JsonConvert.DeserializeObject<GoogleChrome_BookMarkALLModel>(str2); Console.WriteLine("____________________ 皓月书签同步工具 预处理 ______________________"); Console.WriteLine("____________________ 序列化读取结果如下 ______________________"); if (obj.roots.bookmark_bar != null) { Showchildren(0,obj.roots.bookmark_bar.children); } Console.ReadKey(); } 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 + "目录下内容"); index++; Showchildren(index,l.children); index--; } else { Console.WriteLine(GetTreeStr(index) + "书签url:" + l.url); } } } public static string GetTreeStr(int index) { string str = ""; for (int i = 0; i < index; i++) { str += "┈"; } //if (index > 0) //{ str += "└"; //} return str; }
Pre:
皓月左心房 安卓 1.2.0版本特性介绍。
Next:
[哲学]皓月的三百元理论 (应该说悖论)
0
likes
454
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Submit
Sign in
to leave a comment.
No Leanote account?
Sign up now.
0
comments
More...
Table of content
No Leanote account? Sign up now.