【问题标题】:Trying to parse finance.yahoo.com with Mojo and perl尝试使用 Mojo 和 perl 解析 Finance.yahoo.com
【发布时间】:2017-04-29 07:33:40
【问题描述】:

我失败得很惨。我要解析以下网址:

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

并捕捉这三个部分:* 全部 * 新闻 * 新闻稿

这就是我想出的..

#!/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;

任何帮助将不胜感激..谢谢

【问题讨论】:

    标签: perl mojolicious mojo


    【解决方案1】:

    您访问 DOM 的方式不正确。

    解析部分新闻部分的示例如下:

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

    【讨论】:

    • 太棒了!好的。所以,现在我正在尝试在 $ua 中搜索 A HREF,但我无法正确找到它。我将 all_text 更改为内容。我想念如何制定标签,但我快到了。我错过了什么?我的 $dom = Mojo::DOM->new;我的 $content = $ua->$dom->find('href#');
    • @BrianRehder:因为您为上述查询提出了另一个问题。我认为最好接受这个答案作为解决方案并等待你的新问题的答案。见meta.stackexchange.com/questions/5234/…
    猜你喜欢
    • 1970-01-01
    • 2017-04-30
    • 2012-10-28
    • 2013-09-27
    • 2012-11-07
    • 2015-08-18
    • 1970-01-01
    • 2013-11-24
    • 2011-04-25
    相关资源
    最近更新 更多