2021-02-10

Vivaldi - import bookmarks from my website

I have a page on this website where I keep my bookmarks. I find this webpage rather useful since I can avoid syncing bookmarks across different browsers.

What if I want to import the bookmarks into a browser? Let's start by extracting the hyper-links from the page above (web scraping) with this python script:

 #!/usr/bin/env python
 
 from bs4 import BeautifulSoup as bs
 import urllib3
 
 if __name__ == "__main__":
     # upstream repo
     url="https://gitlab.com/Sevepy/wktopelican/-/raw/master/public/My_Bookmarks.wiki.html"
     http = urllib3.PoolManager()
     response = http.request('GET', url)
     
     # ----------------------------------|
     #                                   v Default parser
     html_bookmarks = bs(response.data,"lxml")
     
     # filter out part of interest 
     inner_article = html_bookmarks.find("div",class_="article-content")
     
     # get the urls from the soup :->
     list_of_bookmarks = inner_article.find_all("a",recurive = False)
     
     # pelican wants a title
     header = """
 <!DOCTYPE NETSCAPE-Bookmark>
 <head>
 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
 <TITLE>Bookmarks</TITLE>
 </head>
 <body>
 """
     with open("./public/mybookmarks.html","w") as bookmarks:
         bookmarks.write(header)
         # list of 
         bookmarks.write("\n".join(["<DT>"+anchor+"</DT>" 
             for anchor in map(str,list_of_bookmarks)]))
         bookmarks.write("</body>")
 

It outputs a properly formatted HTML file (mybookmarks.html), which can then be imported straight into a web browser, in this case my Vivaldi web browser.

Open Vivaldi bookmarks manager and you should be able to locate the button import on the right upper side (see the figure below).

From the drop-down menu Import Bookmarks and Settings select Bookmark HTML File and then choose the python script's output file (press the Choose a File button for the file selector dialog). Vivaldi will create a folder named imported with all the new bookmarks inside.

In case you cannot run the script above, you can download the output HTML file here (Right click, Save link as...).