Get HTML table


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get HTML table
# 1  
Old 03-21-2010
Get HTML table

Hi all,

I have a html that contains several tables in it. Need to extract the data from one of them named "orderList". Is it any easy way without using loops.

Thanks
# 2  
Old 03-21-2010
Hello, valigula, and welcome to the forum.

There is almost no chance anyone will be able to help you unless you show us what the html looks like and what it is that you want to extract from it. In short, share a sample of the input data (your html) and a sample of the desired output (how you want it to look afterwards). Make sure to put each sample between code tags so that formatting is not lost.

Regards,
Alister
# 3  
Old 03-22-2010
Thanks for your reply

that is a sort example of the html code

HTML Code:
<html>
<body>
    <table>
        <thead>
            <tr>
                <th>number</th>
                <th>product type</th>
                <th>service activation date</th>
                <th>cease date</th>
                <th>reference</th>
                <th>operator</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td><span id="test-number"><span>01214413277</span></a></td>
                <td><span id="test-productType">Product Name</span></td>
                <td><span id="test-serviceActivationDate">11/12/09</span></td>
                <td><span id="test-ceaseDate"></span></td>
                <td><span id="test-reference">123456789</span></td>
            </tr>
        </tbody>
    </table>
</div>
  <div>
  <table id="orderList">
    <thead>
      <tr>
        <th>order number</th>
        <th>order type</th>
        <th>product type</th>
        <th>status</th>
        <th>status date</th>
      </tr>
    </thead>
    <tbody>
      <tr class="odd">
        <td><span id="orderLink">24904093</a></td>
        <td><span id="orderType">Provide</span></td>
        <td><span id="productType">Product Name</span></td>
        <td><span id="status"></span></td>
        <td><span id="statusDate">15/12/09</span></td>
      </tr>
    </tbody>
  </table>
</body>
</html>
example: i actually need is to find out the status column on the orderList table is completed Y, any other case including null will be N.

24904093, N
# 4  
Old 03-22-2010
Try this code:

Code:
awk -F"[><]" '/orderLink/ { f=1; _ord=$5; } f && /status/ { $5=$5?$5:"N";f=0; print _ord","$5}' file

It worked for the sample input. Please check it for the complete html input and let us know how it goes.

input & output:

Code:
/home/usr2 >cat file
<html>
<body>
    <table>
        <thead>
            <tr>
                <th>number</th>
                <th>product type</th>
                <th>service activation date</th>
                <th>cease date</th>
                <th>reference</th>
                <th>operator</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td><span id="test-number"><span>01214413277</span></a></td>
                <td><span id="test-productType">Product Name</span></td>
                <td><span id="test-serviceActivationDate">11/12/09</span></td>
                <td><span id="test-ceaseDate"></span></td>
                <td><span id="test-reference">123456789</span></td>
            </tr>
        </tbody>
    </table>
</div>
  <div>
  <table id="orderList">
    <thead>
      <tr>
        <th>order number</th>
        <th>order type</th>
        <th>product type</th>
        <th>status</th>
        <th>status date</th>
      </tr>
    </thead>
    <tbody>
      <tr class="odd">
        <td><span id="orderLink">24904093</a></td>
        <td><span id="orderType">Provide</span></td>
        <td><span id="productType">Product Name</span></td>
        <td><span id="status"></span></td>
        <td><span id="statusDate">15/12/09</span></td>
      </tr>
      <tr class="odd">
        <td><span id="orderLink">904093</a></td>
        <td><span id="orderType">Provide</span></td>
        <td><span id="productType">Product Name</span></td>
        <td><span id="status">Y</span></td>
        <td><span id="statusDate">15/12/09</span></td>
      </tr>
    </tbody>
  </table>
</body>
</html>
/home/ansujohn >
/home/ansujohn >cat file
<html>
<body>
    <table>
        <thead>
            <tr>
                <th>number</th>
                <th>product type</th>
                <th>service activation date</th>
                <th>cease date</th>
                <th>reference</th>
                <th>operator</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td><span id="test-number"><span>01214413277</span></a></td>
                <td><span id="test-productType">Product Name</span></td>
                <td><span id="test-serviceActivationDate">11/12/09</span></td>
                <td><span id="test-ceaseDate"></span></td>
                <td><span id="test-reference">123456789</span></td>
            </tr>
        </tbody>
    </table>
</div>
  <div>
  <table id="orderList">
    <thead>
      <tr>
        <th>order number</th>
        <th>order type</th>
        <th>product type</th>
        <th>status</th>
        <th>status date</th>
      </tr>
    </thead>
    <tbody>
      <tr class="odd">
        <td><span id="orderLink">24904093</a></td>
        <td><span id="orderType">Provide</span></td>
        <td><span id="productType">Product Name</span></td>
        <td><span id="status"></span></td>
        <td><span id="statusDate">15/12/09</span></td>
      </tr>
      <tr class="odd">
        <td><span id="orderLink">904093</a></td>
        <td><span id="orderType">Provide</span></td>
        <td><span id="productType">Product Name</span></td>
        <td><span id="status">Y</span></td>
        <td><span id="statusDate">15/12/09</span></td>
      </tr>
    </tbody>
  </table>
</body>
</html>
/home/usr1 >awk -F"[><]" '/orderLink/ { f=1; _ord=$5; } f && /status/ { $5=$5?$5:"N";f=0; print _ord","$5}' file
24904093,N
904093,Y


Last edited by dennis.jacob; 03-22-2010 at 08:41 AM.. Reason: included the sample input I tried
# 5  
Old 03-22-2010
Test in a couple of cases ( with a few modifications and this is just owesome!)

I will totally teted and give you the feed-back in how it went.

Thanks

---------- Post updated at 11:43 AM ---------- Previous update was at 07:06 AM ----------

It works perfectly, i completely tested with over 200 cases and works fine!!!

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Export HTML table

HI , I have a HTML tables as below. It has 2 tables ,I want to extract the second table . Please help me in doing it. <html> <body> <b><br>Running Date: </b>11-JAN-2019 03:07</br> <h2> Schema mapping and info </h2> <BR><TABLE width="100%" class="x1h" cellpadding="1"... (3 Replies)
Discussion started by: deepti01
3 Replies

2. Shell Programming and Scripting

HTML table in email body using C Shell

I am using Sun Solaris ver. 5.10 and trying to send an HTML table in email body using mail command in C shell script. I tried following commands:- #1 mail -m "MIME-Version: 1.0;Content-type:text/html;charset=UTF-8" receiver@mail.com < file.html #2 mail -m "Content-type: text/html;" -s "This... (4 Replies)
Discussion started by: jnrohit2k
4 Replies

3. UNIX for Dummies Questions & Answers

Extract table from an HTML file

I want to extract a table from an HTML file. the table starts with <table class="tableinfo" and ends with next closing table tag </table> how can I do this with awk/sed... ---------- Post updated at 04:34 PM ---------- Previous update was at 04:28 PM ---------- also I want to... (4 Replies)
Discussion started by: koutroul
4 Replies

4. Web Development

Help on filtering the table in HTML

1. how to get the filter option on table so that user can enter the fields which ever they want to print only according to the need ? 2.how to print the full fledge table if there is no value in the rows of the table but it should print the whole rows and column in proper tabular form? (2 Replies)
Discussion started by: sidhi
2 Replies

5. Shell Programming and Scripting

Itinerate throught HTML table

HI all, <html> <body> <div> <table id="orderList"> <thead> <tr> <th>order number</th> <th>order type</th> <th>product type</th> <th>status</th> <th>status date</th> </tr> </thead> <tbody> <tr class="odd"> ... (10 Replies)
Discussion started by: valigula
10 Replies

6. Shell Programming and Scripting

help with a bash script to create a html table

Hi guys as the title says i need a little help i have partisally written a bash script to create a table in html so if i use ./test 3,3 i get the following output for the third arguement in the script i wish to include content that will be replace the A characters in the... (2 Replies)
Discussion started by: dunryc
2 Replies

7. Shell Programming and Scripting

Format txt file as html table

I have a short time to solve a problem, so I need some help. I've searched the forum, but I couldn't find a solution to my problem. I made a script to filter some text and now I have a new requirement to make it available as html table. Problem is that I more than one files with different set... (2 Replies)
Discussion started by: tetreb
2 Replies

8. Shell Programming and Scripting

PHP: Sorting HTML table

Hi All, I have an html table which looks like this: <table align="center" border="1"> <CAPTION><EM>Heading for Table</EM></CAPTION> <tr><td><b>1</b></TD><TD><b>2</b></TD><TD><b>3</b></TD><TD><b>4</b></TD><TD><b>TOTAL</b></TD><TD><b>DATE</b></td></tr> <tr><td>88088283</TD> <TD>87613101</TD>... (1 Reply)
Discussion started by: pondlife
1 Replies

9. Shell Programming and Scripting

Export a HTML table to Xcel

Hello All, I have a perl script that prints a HMTL table. I want to convert this data into a report and this want to export this information into Excel. How can I do this? Regards, garric (3 Replies)
Discussion started by: garric
3 Replies

10. Shell Programming and Scripting

HTML table to CSV

Hi !! I have HTML Tables through which i want to generate graphs, but for creating graphs i need the file in CSV format so can anyone can please help me in how can i convert my HTML table file to CSV format. Thanks in Advance (2 Replies)
Discussion started by: i_priyank
2 Replies
Login or Register to Ask a Question