Trying to parse finance.yahoo.com with Mojo and perl

87 views Asked by At

I'm failing miserably. I want to parse the following URL:

http://finance.yahoo.com/quote/MSFT?ltr=1

And capture these three sections: * All * News * Press Releases

Here's what I've come up with..

#!/bin/perl

use Mojo::UserAgent;
use strict;
use warnings;
use feature 'say';

my $ua_string = "Mozila .. ";
my $url       = "http://finance.yahoo.com/quote/MSFT?p=MSFT";
my $timeout   = "5";

my $ua        = Mojo::UserAgent->new( max_redirects => 5, timeout => $timeout );
$ua->transactor->name($ua_string);

my $content = $ua->get($url)->res->dom->at('#436')->{value};

say $content;

Any help would be appreciated.. Thanks

1

There are 1 answers

2
user3606329 On

The way you access the DOM is not correct.

An example to parse parts of the news section would be:

say $ua->get($url)->res->dom->at('div#quoteNewsStream-0-Stream')->all_text;