Parsing: How to go from HTML to CSV?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing: How to go from HTML to CSV?
# 1  
Old 03-26-2009
Parsing: How to go from HTML to CSV?

Dear all,

I have to parse a large amount of html files, which I would like to transform into comma separated values. The html-files have the following structure:


<tag1> CATEGORY_1 <tag2>
<tag3> HEADER_1 <tag4>
<tag5> paragraph_1 <tag6>
<tag5> paragraph_2 <tag6>
<tag3>HEADER_2 <tag4>
<tag5> paragraph_1 <tag6>
<tag5> paragraph_2 <tag6>
<tag5> paragraph_3 <tag6>
<tag7>

<tag1> CATEGORY_2 <tag2>
<tag3> HEADER_3 <tag4>
<tag5> paragraph_1 <tag6>
<tag3>HEADER_4 <tag4>
<tag5> paragraph_1 <tag6>
<tag5> paragraph_2 <tag6>
<tag7>
.....

Each category contains a different number of headers and each header contains a different number of paragraphs.

I would like to transform the HTML into something looking like the following:

“CATEGORY_1” , “HEADER_1” , “paragraph_1”
“CATEGORY_1” , “HEADER_1” , “paragraph_2”
“CATEGORY_1” , “HEADER_2” , “paragraph_1”
“CATEGORY_1” , “HEADER_2” , “paragraph_2”
“CATEGORY_1” , “HEADER_2” , “paragraph_3”
“CATEGORY_2” , “HEADER_3” , “paragraph_1”
“CATEGORY_2” , “HEADER_4” , “paragraph_1”
“CATEGORY_2” , “HEADER_4” , “paragraph_2”
...

I am fairly new to shell scripting and I have been playing around with awk. I was not able to come up with a satisfying solution yet, so any kind of help would be greatly appreciated.


Many thanks


Philipp







# 2  
Old 03-26-2009
Sounds like a job for Perl and HTML::TreeBuilder
# 3  
Old 03-26-2009
Hi,
thank you for the reply. I will try that, however, I am relcutant to use Perl since I hardly know how the bash shell works. Anyways. Thanks a lot

Phil
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Create html <ui> <li> by parsing text file

Hi you all, this is my first post in this forum. I'm italian (please forgive me) :-) so my english will fail to be correct... Anyway, let's get straight to the point! I have a text file like this: ,,,, Disney: 00961-002,,,, ,Pippo: 00531-002,,, ,,Pluto: 00238-002,, ... (5 Replies)
Discussion started by: alcresio
5 Replies

2. Linux

Parsing - export html table data as .csv file?

Hi all, Is there any out there have a brilliant idea on how to export html table data as .csv or write to txt file with separated comma and also get the filename of link from every table and put one line per rows each table. Please see the attached html and PNG of what it looks like. ... (7 Replies)
Discussion started by: lxdorney
7 Replies

3. UNIX for Dummies Questions & Answers

HTML parsing with UNIX shell script

Hi there, Infra/LEXUS0157/lexus0157.html-<tr><td>Minimum password age</td><td>3 days</td><td>Win2k8 Server</td></tr> How do I extract from this html with unix, I just need the 1.'Minimum password age' & 2. '3 days' parameter. Tried doing so with python, would like to have a better... (7 Replies)
Discussion started by: alvinoo
7 Replies

4. Shell Programming and Scripting

Perl syntax and html ole parsing

Hi gurus I am trying to understand some advanced (for me) perl constructions (syntax) following this tutorial I am trying to parse html: Using Mojo::DOM | Joel Berger say "div days:"; say $_->text for $dom->find('div.days')->each; say "\nspan hours:"; say $_->text for... (1 Reply)
Discussion started by: wakatana
1 Replies

5. Shell Programming and Scripting

html-to-csv

Dear, I have to format an output that is html with the tags outside the standard for a csv file. follows the input file: <table id=tabela BORDER=1 CELLSPACING=0 CELLPADDING=0 slcolor=#ffffcc dragcolor='gray' img='false' col='1' rowTotal='1' height=100% habilita_primeira='1'... (2 Replies)
Discussion started by: He2
2 Replies

6. Shell Programming and Scripting

Parsing HTML, get text between 2 HTML tags

Hi there, I'm quite new to the forum and shell scripting. I want to filter out the "166.0 points". The results, that i found in google / the forum search didn't helped me :( <a href="/user/test" class="headitem menu" style="color:rgb(83,186,224);">test</a><a href="/points" class="headitem... (1 Reply)
Discussion started by: Mysthik
1 Replies

7. Shell Programming and Scripting

BASH parsing for html tags

Hello can anyone help me parse this line. <tr><td>United States of America</td><td>Dollar</td><td>43.309</td></tr><tr><td>Japan</td><td>Yen</td><td>0.5579</td></tr> the line above did not break. so i would like to have a result like this United States of America Dollar 43.309 Japan... (3 Replies)
Discussion started by: doomsayer16
3 Replies

8. Shell Programming and Scripting

2 problems: Mailing CSV file / parsing CSV for display

I have been trying to find a good solution for this seemingly simple task for 2 days, and I'm giving up and posting a thread. I hope someone can help me out! I'm on HPUX, using sqlplus, mailx, awk, have some other tools available, but can't install stuff that isn't already in place (without a... (6 Replies)
Discussion started by: soldstatic
6 Replies

9. UNIX for Advanced & Expert Users

html parsing using unix

hi all, I had raised the same question a few weeks back but forgot to mention a lot of points ... so i am raising a new thread furnishing my requirement ... sorry for that .... here is my problem. i have a html that look like below <tr class="modifications-oddrow"> <td... (2 Replies)
Discussion started by: sais
2 Replies

10. Shell Programming and Scripting

HTML parsing by PERL

i have a HTML report file..its in attachment(a part of the whole report is attached..name "input html.doc").also its source is attached in "report source code.txt" i just want to seperate the datas like in first line it should be.. NHTEST-3848498958-NHTEST-10.2-no-baloo a and so on for whole... (3 Replies)
Discussion started by: avik1983
3 Replies
Login or Register to Ask a Question