0

For a simple example:

I have a html file for Google Chrome backup bookmarks: bookmarks.html

bookmark.html is a backup that have no folders, only have bookmarks.

I want to convert bookmarks.html to the folder BOOKMARKS that contains "URL files" for every bookmark.

Every bookmark name transforms to a filename. Every file can be a HTML file within the content like this:

<html>
<head>
<meta http-equiv="refresh" content="0; url=http://example.com/" />
</head>
</html>

https://superuser.com/questions/986527/how-to-create-a-hyperlink-file

And this is the content of bookmarks.html.

<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!-- This is an automatically generated file.
     It will be read and overwritten.
     DO NOT EDIT! -->
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
    <DT><H3 ADD_DATE="1566283592" LAST_MODIFIED="1566283659" PERSONAL_TOOLBAR_FOLDER="true">Bookmarks bar</H3>
    <DL><p>
        <DT><A HREF="https://www.google.com/" ADD_DATE="1566283606" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACIklEQVQ4jYWSS0iUURTHf/fe8RvHooE2VlT2FNqUGWmNEYUR9lhEEVJhUIsoXOQuap1Rq6KHNQt3LaPAIOxhlNTChUwLMU3NR1CklUzg6xvPd1ro2KhTHjjcA/e8/uf/hzmmqsUiEheRLhHxp/2TiDxQ1aK5+ZmFeSJSrwuYiMRVNZKuMxnFz51zu9T3GX/6iPGmRqS/F5WAUMEawuUVRI5UYjwPEWl2zlUYY8YMgIjUW2vPBkPfSV6uYbKvJ+uW3rZSojfuABAEQdw5d96oajHQqr7P8IUqpL8X43lEjp3EK4mBtfgt75l4+4po7U3cytWZPbcyjUlTidv642ipDu7foX7bh2zgs92jDhHpUlWdbNmuEw15OvqweqE7ZjboCAEFADrSjs1LkRM7NAt3+bWRebfYudFx9XguwFqbwePs9z/mT/6NLdAHMBpex28W0/C1Y1Zy05VFM75nUwiAZVGT/v5sgdcA3UurOPUrxvXOFhJD7fOmdn4LeNc5NbpkfWimv5mWZ8KXFKdfXqInOYBnc6gsPEjZ8mKssbQOtvEkMczYl0oK8z3un4lgppbYkhZS3Fp7bnD0Jxeba+lODmTFviFcxq29NeRHDUEQ1DnnqtNSjohIo3Nutx+keNz9gmf9zfQkB0ChYMkK9q2KcaLwMJFQGFV9Y4w5YIwZzyBBI2lRLcD9PVXN/SdFqlokInUi0iEiE9P+UUTuqurmufl/AKTzsFGmvUNUAAAAAElFTkSuQmCC">Google</A>
        <DT><A HREF="https://stackoverflow.com/" ADD_DATE="1566283626" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABXklEQVQ4jbWQsUsCYRjGn/fuSu/Sk3ALmlzNtoagKRqSaHMKGkKhEOV0KWispSXPQaglAnNobOgfaCyIcgicmxO9zFPv/N5WwTs5gt7x+5739/2eDwgw/bK67HcnBQG4Ag3L0LJ/BoBFDuDzTiGUCAywDC3bNbRtANCrwxaBziRZanAGcjADwR8AX1uGesEZyFGzXwO43VsKn07GaJa5lY/GMefUAYooEvaELDnCEW9M2I1V7GdPg04hlLAM7dYqqut67ftLNwdpMB5dgRfXdVMgHIFpx9egfbwYk0eDA2LKAWJMkK6cUOhOGdkpZmoQiy29OmwFq1AKb5CgQyakAXqQJKpELn/eJzPK1JKhPhHjk4EmMzUVmU/coVLkeXff672pk155YXUsxikCJQFeYVCSgCiAV920N311b+r37FslH413S+qaV86rggfIBbG38RRAN+2ZHzsTMKvGv80vvziHGAusG84AAAAASUVORK5CYII=">Stack Overflow</A>
        <DT><A HREF="https://www.youtube.com/" ADD_DATE="1566283636" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABCElEQVQ4ja2TMU4DMRBF38wiEFIqKFYIUSAtJ8kNcoood8jJopwgRyANNCg1aSJl/Sls73rdoBC+NLI982c8/raNAgIHLC2NKZRHg1BHavKvyDlWOGbAG9ACT8RuSgTgCzgA7wbHstpC8Ck4CSSQzDTMp3ZK3EVOvhN8pGAvCILzYGbnYh0SRynn1oEX4JGpME7bOmaO5Lh7daQAPADPDtwnLSKhaaI2q5Wx2RhdZ4RgTIXOBWde7WyYRWLfw3wOux2s12PhaaFQK30xbqqzCSnu1DSw3cJyCfv9GI+Wu3AEneCY1M23ENS2QWZx7h4G/8j7FrxefY25rz8/pH97ytd/puS8+Dv/AFRGv3m23DwSAAAAAElFTkSuQmCC">YouTube</A>
        <DT><A HREF="https://www.facebook.com/" ADD_DATE="1566283659" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAArUlEQVQ4jWN0yti8leH/fy8GcgAj4zYmsjUzMDAw/P/vxUS2ZihgIUYRDycrQ1aYNoOlnjgDLxcbw9yNNxiW77hNvAGZodoM7paycD4bC8LhRBlgrivOwMDAwNC96ALDzuNPGP7//0+aAYK8bAwMDAwMO449xpCjOBAZndI3/ccluXeGL1bxvqWXGLYefki+Cx6/+EKcC9Bd4pyxGUOO4jAYFgYwMm4jWzcj4zYA2mQtm7CTmFoAAAAASUVORK5CYII=">Facebook </A>
    </DL><p>
</DL><p>
2

You can have the following approach:

  1. Parse bookmarks.html to
    • keep lines containting HREF
    • keep in these lines only what is in HREF="..."
  2. With these strings
    • remove protocol and slash (/)
    • fill a template file with the good name

  • Enter the following code in your favorite editor:


#! /bin/bash

sites=$(sed '/HREF/!d' < $1 | sed 's/.*HREF="\([^ "]*\).*/\1/')

for site in $sites
do
    file=$(echo $site | sed 's/https*:\/\///' | sed 's/\/.*//')

    cat << EOF > $file
    <html>
    <head>
    <meta http-equiv="refresh" content="0; url=$site" />
    </head>
    </html>
    EOF

done
  • Save it as extract.sh
  • In a terminal, make it executable chmod +x extract.sh
  • Use it: ./extract.sh /path/to/bookmark.html
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy