[SOLVED] Shell script or other method to convert firefox bookmark file to excel
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The top ones are just from a firefox bookmark file.
Need to convert them into an excel spreadsheet, preferably
so they are in this format
Code:
A B C
1 CODE Hyperlink URL
2 18010139 18010139 http://www....
3 02230726 02230726 http://www....
I realise I can easily create column B from columns A and C in Excel but columnn C does actually have to be a hyperlink if this is done in one script.
Use Perl, pick an HTML parsing module and pick an Excel writing module (or CSV one). All mentioned categories of modules exist and are well established.
Does this file contains these two samples only. or it contains other text as well ?
Can you assure that each line contains one link only ?
Column A and Column B will be same ?
Saying you don't have time is just an excuse. Time is never enough for everybody, not just you. Its up to yourself to find the time. No time ? then cut down on your parties, spend 1 or 2 hrs before you sleep to learn etc. after all, its for your work right?
Back to topic, you can use Python. Assuming you are not using later version of firefox which uses json instead
Code:
import re
html=open("bookmarks.html","Ur").read()
html=re.split("</[aA]>",html)
sp=re.compile("<a href=|>",re.I|re.DOTALL|re.M)
for item in html:
if "<a href" in item.lower():
chunks=item.split("\n")
whatiwant=sp.split(chunks[0].strip())
if whatiwant[0]=="": whatiwant.pop(0)
try: print whatiwant[0].split()[0],whatiwant[-1]
except: pass
this only gets the data out from the html. you can use csv module to write csv after that.
Last edited by ghostdog74; 04-15-2010 at 09:19 AM.
In case this helps, regarding post #5 -- even the shiny new Firefox can/will export your bookmarks as HTML, even though it uses JSON internally. Select Bookmarks -> Organize -> Import/Backup -> Export HTML, and then you could proceed with post #5 if you like (or whatever method, if your chosen method wants to begin with an HTML-formatted file).
perl -e 'while(<>){ /href="?(.*?)(".*)?>/i; my $url=$1; />(.*)</; my $code = $1; print "$code,$code,$url\n"; }' <file>
that doesn't work since you are not on multiline mode and you can't guarantee every anchor tags end on same line. also the -n option simulates "while(<>)"
Last edited by ghostdog74; 04-15-2010 at 09:22 AM.
that doesn't work since you are not on multiline mode and you can't guarantee every anchor tags end on same line. also the -n option simulates "while(<>)"
Agree, but I took the assumptions [Post #4] and posted it based on that assumptions only. Regarding -n that is something habitual
Quote:
Originally Posted by Sergei Steshenko
Of course it works - until your input HTML file format changes. HTML is not a line oriented format.
"Programming by coincidence" (c).
I respect your thoughts, Given the choice I would have gone for a HTML parser to do so
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.