Skip to content

Instantly share code, notes, and snippets.

@romuloceccon
Created February 23, 2018 08:10
Show Gist options
  • Save romuloceccon/cf4cc7b068574c40c15699dfe25e82ee to your computer and use it in GitHub Desktop.
Save romuloceccon/cf4cc7b068574c40c15699dfe25e82ee to your computer and use it in GitHub Desktop.
List all current IBOV symbols
#! /usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent ();
use HTML::TreeBuilder::XPath;
my $url = "https://br.advfn.com/bolsa-de-valores/bovespa/";
my $ua = LWP::UserAgent->new;
for my $x ("A" .. "Z") {
my $request = HTTP::Request->new(GET => $url . $x);
$request->header('User-Agent' => 'Perl');
my $response = $ua->request($request);
my $status = $response->code;
die "Error while fetching symbols for letter $x: $status"
unless $status >= 200 and $status < 300;
my $tree = HTML::TreeBuilder::XPath->new_from_content(
$response->decoded_content);
for my $row ($tree->findnodes('//table[@id="id_' . $x . '"]/tr')) {
for my $data ($row->findnodes('./td[2]')) {
print $data->as_text() . "\n";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment