I am very new to perl and need some help with extracting a table from a web page. I was able to figure out how to get the page to print with perl today. Now I just need to only extract the information in the table which states the temperature.
My current code is:
# perl
use strict;
# use LWP::Simple;
use LWP::UserAgent;
my $ua = new LWP::UserAgent;
$ua->timeout(120);
my $url='http://MyTempSite/';
my $request = new HTTP::Request('GET', $url);
my $response = $ua->request($request);
my $content = $response->content();
print $content;
I am trying to get the temperature readings from this html file:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><body bgcolor="#C0C0C0" text="#000000" vlink="#800080" link="#0000FF"><P><h1>TempTrax Digital Thermometer</h1><BR><table cellpadding=0 cellspacing=0 border=0><TR><TD>Model:</TD><TD width=10 rowspan=7><BR></TD><TD>E4</TD><TR><TD>Manufacturer:</TD><TD>Sensatronics</TD> </TR><TR><TD>Website:</TD><TD><a href="http://www.sensatronics.com">http://www.sensatronics.com</a></TD></TR><TR><TD>Firmware Version:</TD><TD>1.2</TD></TR><TR><TD>Release Date:</TD><TD>December 16, 2003</TD></TR><TR><TD>Serial Number:</TD><TD>EA8E6L0T121</TD></TR><TR><TD>Unit name:</TD><TD>LiveTempMonitor</TD></TR></TABLE><P><h3>Current temperature readings:</h3><p><table><TR><TD width=200>Probe1:</TD><TD> 75.1</TD></TR>
<TR><TD width=200>Probe2:</TD><TD>-99.9</TD></TR>
<TR><TD width=200>Probe3:</TD><TD>-99.9</TD></TR>
<TR><TD width=200>Probe4:</TD><TD>-99.9</TD></TR>
</table></body></html>
How should I go about getting only the information in the “Current temperature readings” table to be pulled? Thank you all ahead of time for taking a look at this.
1 Answer