LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-01-2005, 10:15 PM   #1
binaryechoes
LQ Newbie
 
Registered: Jul 2005
Posts: 3

Rep: Reputation: 0
Parsing out html with egrep


I need to cut a dynamic piece of content/syntax out of an html file on a
regular basis. The following code is an example of what I need to awk|cat
sed|head|cut|egrep out

<h2>Network Sensor XPUs</h2>
<table class="description" width="90%" cellspacing="1" cellpadding="15"
align="center"><TR><TD WIDTH="10%" ALIGN="center"
class="descriptionHeader"><b>XPU Number</b></TD><TD WIDTH="10%"
ALIGN="center" class="descriptionHeader"><b>Date</b></TD><TD ALIGN="center"
class="descriptionHeader"><b>Description</b></TD><TR>
<TD ALIGN=CENTER class="description" ALIGN="center"><A
HREF="ican'tposturls.no.good"><b>NS_24.22</b></A></TD><TD
class="description" ALIGN="center">11-23-2005</TD><TD
class="description">This critical Content Update XPU (X-Press Update),
featuring
Virtual Patch technology, contains 1 new event and provides
protection for an Internet Explorer vulnerability that allows
remote code execution. For more information about this
vulnerability, see the following X-Force Alert:
</TD>
</TR>

I've tried numerous command options/syntax but I'm still unable to achieve
this.

[user@box]# cat html.file | egrep '[<h2>Network Sensor XPUs</h2>.*</TD>]' >
newhtml.file

So...in essence I need everything from "<h2>Network Sensor XPUs</h2>" ->
"</TR>".

Any help???

Thanks!

- J
 
Old 12-01-2005, 10:31 PM   #2
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,545

Rep: Reputation: 57
Don't post in more than one forum tool.
 
Old 12-02-2005, 11:49 PM   #3
binaryechoes
LQ Newbie
 
Registered: Jul 2005
Posts: 3

Original Poster
Rep: Reputation: 0
So here's what I ended up with...

Code:
#!/usr/bin/perl 

use LWP::Simple;
use File::Compare;
use File::Copy;
use MIME::Lite;

$page = get("http://www.iss.net/db_data/xpu/RSNS.php");
$html = $page;
$temp = "/var/spool/iss/test/temp.html";
$archive = "/var/spool/iss/test/archive.html";
$mimelite = "/var/spool/iss/test/mimelite.pl";

#sanitize output
$html =~ m|</h2>(.+?)</TR>|s;
#print "$1\n";

open OUTPUT, ">$temp";
print OUTPUT "$1\n";
close OUTPUT;


if (compare("$temp","$archive") == 1) {
### Create the multipart "container":
    $msg = MIME::Lite->new( 
                 To      =>'user@myemailaddy',
                 Subject =>'ISS Sensor Updates',
                 Type    =>'multipart/related'
		 );

    $msg->attach(Type => 'text/html',
                 Data => "New ISS Sensor updates are available.<br>"
                 );

    $msg->attach(Type     =>'text/html',
                 Path     =>'/var/spool/iss/test/archive.html',
                 Filename =>'archive.html',
		 Disposition => 'inline'
		 );

    $msg->send();
}

unlink $archive;
move($temp, $archive);
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Parsing out html with egrep binaryechoes Linux - Newbie 3 12-02-2005 12:41 AM
Parsing HTML Source Code Itsu Linux - General 4 10-08-2005 01:44 AM
HTML parsing library nodger Programming 1 09-01-2005 01:42 AM
HTML parsing with HTML::TreeBuilder smaida Programming 0 07-10-2005 09:58 PM
Parsing HTML using Perl smaida Programming 2 05-29-2004 01:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration