D
dysgraphia
I am new to Perl and also to the Mechanize module.
So far I have obtained a table, table[4] below, with
useful text I would like to put into a tabular format like:
List Position Patient Name Weight Height Clinic Doctor
but I am unsure as to how to proceed.
I will want to send the data to an Access db later so hopefully this
format will be amenable to this.
Any suggestions or assistance appreciated!
Below is my code followed by the relevant portion of html.
In practice the daily list may vary in length up to about 30 patients.
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize;
use HTTP::Cookies;
my $mech = WWW::Mechanize->new(
agent => 'Mozilla/4.0',
cookie_jar => {}
);
$url = 'http://www.somemedicaldata'; # not a real page
$mech->get($url);
unless ($mech->success) {
die "Cannot get login page $url: ",
$mech->response->status_line;
}
my $content = $mech->content();
print "Content is: \"$content\"\n";
# get table data
my @table;
my $tmp = $content;
my $tablecount=0;
while (my $result=$tmp=~/(?=\x3CTABLE).*?(?=\x3C\/TABLE\x3E)/igsm)
{
$tablecount++;
$table[$tablecount]= $&;
}
print "Number of tables: \"$tablecount\"\n";
# table4 has the useful data
my ($dd1,$dd2) = split('<tr class="texttab" ',$table[4]);
$table[4] = $dd2;
# Save table4 raw to see what is collected
open(FH, ">table4raw.txt");
print FH $table[4];
close(FH);
# end of code
This is the table4 html:
<table width="741" border="0" cellpadding="2" cellspacing="1">
<tr bgcolor="#CC9966"
class="texttab"> <td><div align="center"><font
color="#663300"><strong>List
Position</strong></font></div></td>
<td><div align="center"><font
color="#663300"><strong>Patient Name</strong></font></div></td>
<td><div
align="center"><font
color="#663300"><strong>Weight</strong></font></div></td>
<td><div align="center"><font
color="#663300"><strong>Height</strong></font></div></td>
<td><div align="center"><font
color="#663300"><strong>Clinic</strong></font></div></td>
<td><div align="center"><font
color="#663300"><strong>Doctor</strong></font></div></td>
</tr> <tr
class="texttab" > <td
align="center">1</td> <td align="center">A Smith
</td>
<td align="center">78.0</td> <td
align="center">185</td>
<td align="center">AM</td> <td align="center">F
Magoo</td> </tr>
<tr class="texttab" bgcolor=#FFFFFF >
<td
align="center">2</td> <td align="center">B
Smith</td> <td
align="center">56.0</td> <td
align="center">165</td> <td
align="center">PM</td> <td align="center">L
Magee</td> </tr>
<tr class="texttab" >
<td align="center">3</td>
<td align="center">C Smith </td>
<td
align="center">66.0</td> <td
align="center">171</td> <td
align="center">RM</td> <td align="center">R
Magaa</td> </tr>
So far I have obtained a table, table[4] below, with
useful text I would like to put into a tabular format like:
List Position Patient Name Weight Height Clinic Doctor
but I am unsure as to how to proceed.
I will want to send the data to an Access db later so hopefully this
format will be amenable to this.
Any suggestions or assistance appreciated!
Below is my code followed by the relevant portion of html.
In practice the daily list may vary in length up to about 30 patients.
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize;
use HTTP::Cookies;
my $mech = WWW::Mechanize->new(
agent => 'Mozilla/4.0',
cookie_jar => {}
);
$url = 'http://www.somemedicaldata'; # not a real page
$mech->get($url);
unless ($mech->success) {
die "Cannot get login page $url: ",
$mech->response->status_line;
}
my $content = $mech->content();
print "Content is: \"$content\"\n";
# get table data
my @table;
my $tmp = $content;
my $tablecount=0;
while (my $result=$tmp=~/(?=\x3CTABLE).*?(?=\x3C\/TABLE\x3E)/igsm)
{
$tablecount++;
$table[$tablecount]= $&;
}
print "Number of tables: \"$tablecount\"\n";
# table4 has the useful data
my ($dd1,$dd2) = split('<tr class="texttab" ',$table[4]);
$table[4] = $dd2;
# Save table4 raw to see what is collected
open(FH, ">table4raw.txt");
print FH $table[4];
close(FH);
# end of code
This is the table4 html:
<table width="741" border="0" cellpadding="2" cellspacing="1">
<tr bgcolor="#CC9966"
class="texttab"> <td><div align="center"><font
color="#663300"><strong>List
Position</strong></font></div></td>
<td><div align="center"><font
color="#663300"><strong>Patient Name</strong></font></div></td>
<td><div
align="center"><font
color="#663300"><strong>Weight</strong></font></div></td>
<td><div align="center"><font
color="#663300"><strong>Height</strong></font></div></td>
<td><div align="center"><font
color="#663300"><strong>Clinic</strong></font></div></td>
<td><div align="center"><font
color="#663300"><strong>Doctor</strong></font></div></td>
</tr> <tr
class="texttab" > <td
align="center">1</td> <td align="center">A Smith
</td>
<td align="center">78.0</td> <td
align="center">185</td>
<td align="center">AM</td> <td align="center">F
Magoo</td> </tr>
<tr class="texttab" bgcolor=#FFFFFF >
<td
align="center">2</td> <td align="center">B
Smith</td> <td
align="center">56.0</td> <td
align="center">165</td> <td
align="center">PM</td> <td align="center">L
Magee</td> </tr>
<tr class="texttab" >
<td align="center">3</td>
<td align="center">C Smith </td>
<td
align="center">66.0</td> <td
align="center">171</td> <td
align="center">RM</td> <td align="center">R
Magaa</td> </tr>