Posted By

xXxPizzaBreakfastxXx on 01/08/15


Tagged

web user bookmarks favourites


Versions (?)

Bookmark editing (filter links)


 / Published in: C#
 

This is a simple example to quickly and easily produce a set of links for a given site in your bookmarks from Firefox..

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace HtmlParse
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. List<string> yt_links = new List<string>();
  15. //list of (html code <A> </A> for a link).
  16.  
  17.  
  18. StreamReader sr = new StreamReader(@"F:/old-bookmarks.html");
  19. string line = "";
  20.  
  21. while ( (line = sr.ReadLine()) != null )
  22. {
  23. //..
  24.  
  25. //contains youtube link?
  26. if(line.Contains("A HREF=\"http://www.youtube.com/watch"))
  27. {
  28. yt_links.Add(line);
  29. }
  30.  
  31. }
  32.  
  33.  
  34.  
  35.  
  36.  
  37. StreamWriter sw = new StreamWriter(@"F:\yt_old_bookmarks.html");
  38. sw.WriteLine("<!DOCTYPE NETSCAPE-Bookmark-file-1>" +
  39. "<!-- This is an automatically generated file." +
  40. " It will be read and overwritten." +
  41. "DO NOT EDIT! -->" +
  42. "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">" +
  43. "<TITLE>Bookmarks</TITLE>" +
  44. "<H1>Bookmarks Menu</H1>" +
  45. "<DL><p>");
  46.  
  47. foreach(string link in yt_links)
  48. {
  49. sw.WriteLine(link);
  50. }
  51.  
  52. sw.WriteLine("</DL><p>" +
  53. " </DL><p>" +
  54. "</DL><p>" );
  55.  
  56.  
  57. sw.Flush();
  58. sw.Close();
  59.  
  60.  
  61. }
  62. }
  63. }

Report this snippet  

You need to login to post a comment.