Solved

Extracting records from an html page

Posted on 2004-04-16
3
147 Views
Last Modified: 2010-03-04
Hi all,
This is my very first post. I have a network appliance that sends me daily reports in html format. The goal is to input this daily data in an xl spreadsheet.

The format looks like this.

Daily Incoming Report : 01/01/2003
   Totals and Averages:
   Total Message Count                    87140
   Total Message Count (Encrypted/Signed) 10
   Total Messages (with SSL)              1498
   Total Messages (without SSL)           85642
   Total Message Volume (MB)              1441.18
   Average Messages per Hour              3630.83
   Average Volume per Hour (MB)           60.05


So far I have discovered two choices.
1, use lynx -dump html_file.html > text_file.txt which strips all the html tags, I then use sed to pull the lines I am interested in.
The dilema is to imprt those lines and files into xl.

2, I looked here and found this, but am not sure how to use it.
http://search.cpan.org/~msisk/HTML-TableExtract-1.08/lib/HTML/TableExtract.pm


Any help will be greatly appreciated.
Thanks

Noob
0
Comment
Question by:perlnoob
3 Comments
 
LVL 3

Accepted Solution

by:
PerlKing earned 50 total points
ID: 10847941
If my understanding is correct, you know how to extract the data from the HTML tables (using either of the above mentioned approaches) but you don't know how to create an xl sheet.

I can think of two alternatives:
1. If your requirement is simple and you need just a single-sheet xl page, then all you need to do is to print the data in comma seperated format (csv). For example, in the documentation link of TableExtract.pm that you mentioned, you can see the following spippet of code in the Snopsys section:

 # Examine all matching tables
 foreach $ts ($te->table_states) {
   print "Table (", join(',', $ts->coords), "):\n";
   foreach $row ($ts->rows) {
      print join(',', @$row), "\n";
   }
 }

This code prints the extracted data in a csv format. Just make this write into a file instead and name the file "something.csv". xl will be able to open this file for you.

2. If you need a more sophisticated xl sheet to be created you, could use this module
http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-0.42/WriteExcel.pm

Hope that helped
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question