请修改上述程序,以便用您选择的图片替换任何页面内的所有图像(例如.jpg或.gif图像)。当HTML网页包含图像时,浏览器将识别这些图像URL,并为每个图像发送URL请求。您应该能够在URL重写程序中看到URL。您只需要确定URL是否正在尝试获取特定类型的图像文件;如果是,您可以用另一个(您选择的)替换该URL。
use strict;
use warnings;
# Forces a flush after every write or print on the STDOUT
select STDOUT; $| = 1;
# Get the input line by line from the standard input.
# Each line contains an URL and some other information.
while (<>)
{
my @parts = split;
my $url = $parts[0];
# If you copy and paste this code from this PDF file,
# the ˜ (tilde) character may not be copied correctly.
# Remove it, and then type the character manually.
if ($url =˜ /www\.cis\.syr\.edu/) {
# URL Rewriting
print "http://www.yahoo.com\n";
}
else {
# No Rewriting.
print "\n";
}
}