Skip to content

Instantly share code, notes, and snippets.

@kidd
Created February 4, 2010 15:33
Show Gist options
  • Select an option

  • Save kidd/294755 to your computer and use it in GitHub Desktop.

Select an option

Save kidd/294755 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use HTML::TreeBuilder;
use LWP::UserAgent;
use Data::Dump qw(ddx dump);
sub getShippingRate {
#http://www.iberlibro.com/servlet/ShipRates?vid=51947087
my ($id) =@_;
my $response = LWP::UserAgent->new->request(
HTTP::Request->new( GET =>
"http://www.iberlibro.com/servlet/ShipRates?vid=$id")); #$id
my $tree = HTML::TreeBuilder->new();
$tree->parse($response->content);
$tree->eof;
my $t = ($tree->look_down(
'_tag', 'table', 'class','data'
))[0];
my $row = ($t->look_down('_tag' , 'tr'))[1];
my $col = ($row->look_down('_tag', 'td'))[1];
print $col->as_text;
}
getShippingRate('a');
die;
my $tree= HTML::TreeBuilder->new;
$tree->parse_file('sr.html');
#$tree->dump;
my $root = $tree->root;
my @a = $root->find('table');
@a = $root->look_down('class','result');
foreach (@a) {
my $price = $_->look_down('class','price');
my $scndInfo = $_->look_down('class','shipping');
$scndInfo = $scndInfo->look_down('class','scndInfo');
print $price->as_text , "\n";
my @b = $scndInfo->extract_links();
my %h;
foreach my $link (@b) {
print $link->[0]->[0] , "\n";
my ($id) = $link->[0]->[0] =~ /vid=(.+)$/;
#http://www.iberlibro.com/servlet/ShipRates?vid=51947087
#$h{$1}
}
#ddx \@b;
#print $_->dump;
}
$tree->delete;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment