我正在尝试抓取位于 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/