Hi all.
I have considered writing a news retrieval application for a few weeks. Essentially, I envision it has having the following capabilities:
- When 'fed' a list of keywords, it will search an array of news related sites ( http://news.yahoo.com, http://www.google.com, etc.) for stories that contain the keywords mentioned above.
- Since the articles are often (if not consistantly) accessible behind a hyperlink, my program needs to be able to follow them. One prime example being http://www.perl.com. It has an article entitled 'A Chromosome at a Time with Perl, Part 1'. The fact that it is behind a link adds another layer of complexity to my objective.
- After having made it's daily 'sweeps', each complete article would be stored on my local machine in HTML form so I could peruse them at my leisure.
I am considering using WWW::Mechanize but having never used it, I would greatly appreciate advice from those who have or any feedback from those who might suggest an alternate course of action. Included below, is my fledging foray into this vast arena.
use warnings;
use strict;
use LWP::UserAgent;
my $agent = LWP::UserAgent->new();
my $site = 'http://www.perl.com';
my $response = $agent->get( $site );
my $content = $response->content();
if( $content =~ m/Chromosome/i ) {
open( FH, ">>news.html" ) || die "Error : $!\n";
print FH $content;
close( FH ) || die "Error : $!\n";
}
else {
print "Nothing!\n";
}
Thanks,
-Katie.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.