-
-
Save zsan/357260 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/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