public static void extract_favicon1(string filename) { string html = System.IO.File.ReadAllText(filename); afh.HTML.HTMLDocument doc = afh.HTML.HTMLDocument.Parse(html); using (System.IO.StreamWriter sw = new System.IO.StreamWriter("bm_favicons.css")){ sw.WriteLine("/* favicons */"); sw.WriteLine("li[favicon]{padding-left:20px;background-position:left top;background-repeat:no-repeat;margin-bottom:2px;}"); //Gen::Dictionary<string,string> dict=new Gen::Dictionary<string,string>(); //foreach(afh.HTML.HTMLElement a in doc.enumElementsByTagName("a",false)){ // string k=a.getAttribute("icon_uri",false); // if(k==null||k==""||dict.ContainsKey(k))continue; // string data=a.getAttribute("icon",false); // if(data=="")data=k; // dict.Add(k,data); // sw.WriteLine("li[favicon=\"{0}\"]{{background-image:url({1});}}",k,data); //} //foreach(afh.HTML.HTMLElement a in doc.enumElementsByTagName("a",false)){ // string k=a.getAttribute("icon_uri",false); // if(k==null||k=="")continue; // string data=a.getAttribute("icon",false); // if(data=="")data=k; // sw.WriteLine("li[favicon=\"{0}\"]{{background-image:url({1});}}",k,data); //} Gen::SortedList <string, string> dict = new Gen::SortedList <string, string>(); foreach (afh.HTML.HTMLElement a in doc.enumElementsByTagName("a", false)) { string k = a.getAttribute("icon_uri", false); if (k == null || k == "") { continue; } string data = a.getAttribute("icon", false); if (dict.ContainsKey(k) && dict[k] != "") { continue; } dict[k] = data; } foreach (Gen::KeyValuePair <string, string> p in dict) { string k = p.Key; string d = p.Value; if (d == "") { d = k; } sw.WriteLine("li[favicon=\"{0}\"]{{background-image:url({1});}}", k, d); } } }
public static void extract_favicon2(string filename) { string html = System.IO.File.ReadAllText(filename); afh.HTML.HTMLDocument doc = afh.HTML.HTMLDocument.Parse(html); // read bookmarks.html Gen::SortedList <string, string> dict = new Gen::SortedList <string, string>(); foreach (afh.HTML.HTMLElement a in doc.enumElementsByTagName("a", false)) { string k = a.getAttribute("icon_uri", false); if (k == null || k == "") { continue; } string data = a.getAttribute("icon", false); if (dict.ContainsKey(k) && dict[k] != "") { continue; } dict[k] = data; } // output xml using (System.IO.StreamWriter sw = new System.IO.StreamWriter("bm_fav.xml")){ sw.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); sw.WriteLine("<favicons>"); foreach (Gen::KeyValuePair <string, string> p in dict) { string k = p.Key; string d = p.Value; sw.WriteLine(" <favicon url=\"{0}\" data=\"{1}\" />", k, d); } sw.WriteLine("</favicons>"); } // output css using (System.IO.StreamWriter sw = new System.IO.StreamWriter("bm_fav.css")){ sw.WriteLine("/* favicons */"); sw.WriteLine("li[favicon]{padding-left:20px;background-position:left top;background-repeat:no-repeat;margin-bottom:2px;}"); foreach (Gen::KeyValuePair <string, string> p in dict) { string k = p.Key; string d = p.Value; if (d == "") { d = k; } sw.WriteLine("li[favicon=\"{0}\"]{{background-image:url({1});}}", k, d); } } }