Skip to content

Instantly share code, notes, and snippets.

@zsan
Forked from anonymous/gist:357253
Created April 6, 2010 05:43
Show Gist options
  • Save zsan/357260 to your computer and use it in GitHub Desktop.
Save zsan/357260 to your computer and use it in GitHub Desktop.
/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize;
use HTML::TreeBuilder;
my $agent = WWW::Mechanize->new();
$agent->get("http://www.gumtree.com/london/79/52349379.html");
#my $mail2 = get_mail($agent->content);
#kalo nilai yang mau dibalikin berupa array maka terima sebagai array
my @mail2 = get_mail($agent->content);
print $mail2;
sub get_mail {
my $mail = shift;
my $node = HTML::TreeBuilder->new();
$node->parse($mail);
my @class = $node->find_by_attribute('id' => 'posting_details');
my @tables = $class[0]->find_by_attribute('id' => 'desc');
my @all_mails;
foreach my $table(@tables) {
my $p = $table->look_down(_tag => 'p');
my $email_ref = $p->look_down(_tag => 'a');
my $email = $email_ref->attr('href') if ref $email_ref;
$email = 'n/a' unless ref $email_ref;
#print "$email\n";
push @all_mails, $email;
}
$node->delete;
return @all_mails;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment