通过递增URL和下载 [英] Incrementing Through URLs and Downloading
问题描述
我只想说递增一个URL一个数字和下载从那里把信息的简单浏览器的自动化。例如,如果地址是这样的:
I would just like a simple browser automation that increments one number in a URL and downloads the information from that place. For example, if the address looks like this:
www.test.com/something/part1_0.jpg
www.test.com/something/part1_0.jpg
我怎么能递增'1'和下载从每个连续的网页文件?
How could I increment the '1' and download the file from each successive web page?
感谢
P.S。我使用的是OS X 10.9
P.S. I'm using OS X 10.9
推荐答案
下面是一个使用的开放式URI :
require 'open-uri'
(1..100).each do |num|
File.open("part#{num}_0.jpg", 'wb') do |f|
f.write open("www.test.com/something/part#{num}_0.jpg").read
end
end
这个片断A)创建了一个数字范围; B)在号码范围迭代; C)以二进制方式打开图像文件,内插的当前数量到文件名;和D)读取URL中的图像,并将其写入。
This snippet A) creates a range of numbers; B) iterates over the range of numbers; C) opens an image file in binary mode and interpolates the current number into the file name; and D) reads the image from the URL and writes it.
但最简单的方法很可能是使用卷曲从你的命令行:
But the easiest way would probably be to use curl from your command line:
curl -O www.test.com/something/part[1-100]_0.jpg
根据所需要访问的网页的数量,修改相应括号中的数字。
Depending on the number of webpages that you need to access, modify the numbers in brackets accordingly.
这篇关于通过递增URL和下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!