App-CryptoCurrencyUtils

 view release on metacpan or  search on metacpan

lib/App/CryptoCurrencyUtils.pm  view on Meta::CPAN

    my $res = HTTP::Tiny->new->get("https://coinmarketcap.com/all/views/all/");
    return [$res->{status}, $res->{reason}] unless $res->{success};

    my @coins;

    # we capture the records first to speed up otherwise-glacial matching
    my @trs;
    while ($res->{content} =~ m!(<tr \s id="id-[\w-]+".+?</tr>)!gsx) {
        push @trs, $1;
    }
    #say "D:found ", scalar(@trs), " coins";

    my $i = 0;
    for my $tr (@trs) {
        $i++;
        $tr =~
            m!<tr \s id="id-(?<safename>[\w-]+)"[^>]*>.+?
              <td \s class="text-center">\s*(?<rank>\d+)\s*</td>.+?
              <td \s class="[^"]*?col-symbol">(?<symbol>[^<]+)<.+?
              <td \s class="[^"]*?market-cap[^"]*" \s data-usd="(?<mktcap_usd>[^"]+)" \s data-btc="(?<mktcap_btc>[^"]+)".+?
              <a \s href="[^"]+" \s class="price" \s data-usd="(?<price_usd>[^"]+)" \s data-btc="(?<price_btc>[^"]+)".+?



( run in 0.623 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )