perl - 从 .asp url 抓取图像并保存

标签 perl imagedownload

我正在尝试抓取位于 here 的图像 每天几次将其保存在我的服务器中,就像我“右键单击”图像并将其保存在我的桌面上一样。我已决定使用 perl 脚本来执行此操作,这是我到目前为止所写的内容:

use Image::Grab;
 $pic->regexp('.*\.png');
 $pic->search_url('http://www.reuters.wallst.com/enhancements/chartapi/index_chart_api.asp?symbol=.SPX&headerType=quote&width=316&height=106&duration=3');
 $pic->grab;
open(IMAGE, ">index_chart_api.png") || die"index_chart_api.png: $!";
 binmode IMAGE;  # for MSDOS derivations.
 print IMAGE $pic->image;
 close IMAGE;

通过 ssh 运行它后,我收到此错误:无法在第 2 行的未定义值上调用方法“regexp”

任何人都知道“$pic->regexp('.*.png');”这一行有什么问题或者如何从服务器上提到的 url 中正确抓取并保存此图像 (index_chart_api.png)?

感谢任何帮助。

最佳答案

请注意,给出的 URL 在我的浏览器中显示了 PNG 图像,这意味着没有用于搜索图像的 HTML。那么,原则上,以下脚本应该可以工作:

#!/usr/bin/env perl

use warnings; use strict;
use LWP::Simple qw(getstore is_error);

my $img_url = 'http://www.reuters.wallst.com/enhancements/chartapi/index_chart_api.asp?symbol=.SPX&headerType=quote&width=316&height=106&duration=3';

my $ret = getstore($img_url, 'test.png');

if (is_error($ret)) {
    die "Error: $ret\n";
}

我使用了类似的脚本来生成 Norwegian Sun in the Baltic Sea - 6 days in 5 minutes .

关于perl - 从 .asp url 抓取图像并保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7814827/

相关文章:

Perl grep 相似的单词

Windows文件输出重定向问题

ios - 如果图像实际上是从 url 下载的,我如何在 swift 5 中知道?

java - 如何放置静态图像直到使用 picasso 从 url 下载图像

Android,在列表适配器中有效地加载图像

python异步图像下载(多个url)

python - 使用 perl 或 python 加强自动化

regex - Perl 可选捕获组不起作用?

arrays - Perl 中的哈希变量和数组给出了一个尴尬的输出

ios - 按顺序异步下载图片