Thanks :)
Actually, I've never used WWW::Mechanize, so it didn't occur to me to try that. The routine I use for scraping the data from the Monk homenodes is given below. I think the main performance hit is the fact that I need to issue a separate request for each Monk. Ideally, it would be good to be able to grab all this information in a single go. But I'm not aware of any way that this is currently possible.
sub get_monk_stats {
my $ref = shift;
my $monk_url = 'http://www.perlmonks.org/?node_id=';
my %monk_fields = (
'User since:' => 1,
'Last here:' => 1,
'Experience:' => 1,
'Level:' => 1,
'Writeups:' => 1,
);
MONK:
foreach my $id (keys %{$ref}) {
print "Getting data for $ref->{$id}{name} ($id)\n";
my $ua = LWP::UserAgent->new();
my $req = HTTP::Request->new(GET=>"$monk_url$id");
my $result = $ua->request($req);
next MONK if !$result->is_success;
my $content = $result->content;
my $p = HTML::TokeParser->new(\$content);
while (my $tag = $p->get_tag("td")) {
my $text = $p->get_trimmed_text("/td");
if ($monk_fields{$text}) {
$p->get_tag("td");
$ref->{$id}{$text} = $p->get_trimmed_text("/td");
}
}
}
return $ref;
}
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, 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, 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.
|
|