I remember you came here a while ago asking for advise on how to automatically parse online staff info html pages into useful data. How far are you into your project anyway? Did you experiment with the various CPAN modules mentioned in the replies to your original post?
Ok, I have written a demo using the following modules:
LWP::UserAgent ... to fetch the HTML source
HTML::Strip ... to strip HTML tags
use strict;
use warnings;
use LWP::UserAgent;
use HTML::Strip;
# fetch the html source
my $ua = new LWP::UserAgent;
my $req = new HTTP::Request (GET => 'http://www.ntu.edu.sg/eee/eee4/cv
+/eekteoh.htm');
my $res = $ua->request($req);
die "unable to fetch HTML source: $res->status_line"
if !$res->is_success();
my $html = $res->content(); # fetch the html source
$html =~ s/\x0D//g; # convert to unix format
# grab the html fragments
my ($research_interest, $selected_publications) = $html =~
/(Research Interests.*)(Selected Publications.*)Projects/s;
# strip html tags
my $hs = HTML::Strip->new();
$research_interest = $hs->parse( $research_interest );
$research_interest =~ s/\n+/\n/sg;
$research_interest =~ s/(Research Interests)/$1\n------------------/;
$selected_publications = $hs->parse($selected_publications);
$selected_publications =~ s/\n+/\n/sg;
$selected_publications =~ s/(Selected Publications)/$1\n--------------
+-------/;
$hs->eof;
print "$research_interest\n\n$selected_publications";
And the output -
Research Interests
------------------
Computer Vision and Pattern Recognition
Autonomous Navigation of Outdoor AGVs
Intelligent Systems
Robotics
Industrial Automation
Selected Publications
---------------------
DG Shen, Harace HS Ip, ....
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|