Ruby Vikas从wallperswide.com下载';剧本

Ruby Vikas从wallperswide.com下载';剧本,ruby,Ruby,我是一个彻头彻尾的傻瓜,但我试着从wallperswide.com下载壁纸 使用Vikas的Ruby脚本可在以下页面找到: 我运行的是64位Windows 7,以前下载并安装过以下软件 运行脚本: rubyinstaller-1.9.3-p125.exe wget-1.11.4-1-setup.exe 来自日本的nokogiri 我没有安装“openuri”,因为我不知道如何安装 我复制了脚本并将其保存为txt文件,并将扩展名改为.rb和 已运行该文件,但命令提示符窗口中显示以下错误消息: 该

我是一个彻头彻尾的傻瓜,但我试着从wallperswide.com下载壁纸 使用Vikas的Ruby脚本可在以下页面找到:

我运行的是64位Windows 7,以前下载并安装过以下软件 运行脚本:

rubyinstaller-1.9.3-p125.exe

wget-1.11.4-1-setup.exe

来自日本的nokogiri

我没有安装“openuri”,因为我不知道如何安装

我复制了脚本并将其保存为txt文件,并将扩展名改为.rb和 已运行该文件,但命令提示符窗口中显示以下错误消息: 该命令的语法不正确

请提供详细的帮助。谢谢

脚本如下:

#!/usr/bin/env ruby
#
#  Vikas Reddy
#
#  A little script to download ALL the wallpapers of a given
#  resolution from http://www.wallpaperswide.com/
#
#  Requirements
#  ============
#  Ruby Version: 1.9.2
#  Gems: nokogiri, open-uri
#  Other programs: wget
#
#
#  Available Resolutions
#  =====================
#
#  Wide
#  
#  * 16:10 960x600
#  * 16:10 1152x720
#  * 16:10 1280x800
#  * 16:10 1440x900
#  * 16:10 1680x1050
#  * 16:10 1920x1200
#  * 16:10 2560x1600
#  * 16:10 3840x2400
#  * 16:10 5120x3200
#  * 5:3 800x480
#  * 5:3 1280x768
#  
#  HD
#  
#  * 16:9 960x540
#  * 16:9 1024x576
#  * 16:9 1280x720
#  * 16:9 1366x768
#  * 16:9 1600x900
#  * 16:9 1920x1080
#  * 16:9 2048x1152
#  * 16:9 2400x1350
#  * 16:9 2560x1440
#  * 16:9 3554x1999
#  * 16:9 3840x2160
#  
#  Standard
#  
#  * 4:3 800x600
#  * 4:3 1024x768
#  * 4:3 1152x864
#  * 4:3 1280x960
#  * 4:3 1400x1050
#  * 4:3 1440x1080
#  * 4:3 1600x1200
#  * 4:3 1680x1260
#  * 4:3 1920x1440
#  * 4:3 2048x1536
#  * 4:3 2560x1920
#  * 4:3 2800x2100
#  * 4:3 3200x2400
#  * 4:3 4096x3072
#  * 5:4 1280x1024
#  * 5:4 2560x2048
#  * 5:4 3750x3000
#  
#  Mobile Ratio
#  
#  * VGA 240x320
#  * VGA 480x640
#  * VGA 320x240
#  * VGA 640x480
#  * WVGA 240x400
#  * WVGA 480x800
#  * WVGA 400x240
#  * WVGA 800x480
#  * HVGA 320x480
#  * HVGA 480x320
#  * HVGA 640x960
#  * HVGA 960x640
#  * iPad 1024x768
#  * iPad 768x1024
#  * HD 16:9 480x272
#  * HD 16:9 272x480
#  * Phone 176x220
#  * Phone 220x176
#  
#  Dual
#  
#  * 4:3 1600x600
#  * 4:3 2048x768
#  * 4:3 2304x864
#  * 4:3 2560x960
#  * 4:3 2800x1050
#  * 4:3 2880x1080
#  * 4:3 3200x1200
#  * 4:3 3360x1260
#  * 4:3 3840x1440
#  * 4:3 4096x1536
#  * 4:3 5120x1920
#  * 4:3 5600x2100
#  * 4:3 6400x2400
#  * 4:3 8192x3072
#  * 5:4 2560x1024
#  * 5:4 5120x2048
#  * 5:4 7500x3000
#  * 5:4 10240x4096
#  * 16:10 1920x600
#  * 16:10 2304x720
#  * 16:10 2560x800
#  * 16:10 2880x900
#  * 16:10 3360x1050
#  * 16:10 3840x1200
#  * 16:10 5120x1600
#  * 16:10 7680x2400
#  * 16:10 10240x3200
#  * 5:3 1600x480
#  * 5:3 2560x768
#  * 16:9 1920x540
#  * 16:9 2048x576
#  * 16:9 2560x720
#  * 16:9 3200x900
#  * 16:9 3840x1080
#  * 16:9 4096x1152
#  * 16:9 4800x1350
#  * 16:9 5120x1440
#  * 16:9 7108x2000
#  * 16:9 7680x2160
#  * 3:2 2880x960
#  * 3:2 4000x1333
#  * 3:2 2304x768
#  
#  Other
#  
#  * 3:2 1152x768
#  * 3:2 1440x960
#  * 3:2 2000x1333


require 'open-uri'
require 'nokogiri'

Resolution = "1600x900"
Base_URL   = "http://wallpaperswide.com/#{Resolution}-wallpapers-r/page/"
Output_Directory = "/home/vikas/Wallpapers/"

# Create the Output_Directory if needed
`mkdir -p "#{Output_Directory}"`

(1..2492).each do |page_num|

# Go page by page
url = Base_URL + page_num.to_s

# Parse html
f = open(url)
doc = Nokogiri::HTML(f)

# Loop over image-boxes
doc.css("div.thumb").each do |wallp|

# Extract wallpaper subpage url
wallp.css("div[onclick]").attr("onclick").value =~ /prevframe_show\('(.*)'\)/
subpage_url = $1
subpage_url =~ %r|http://wallpaperswide\.com/[^/]+/([\w\d]+)\.html|

# Generate url of the required wallpaper
wallp_url = %|http://wallpaperswide.com/download/#{$1}-#{Resolution}.jpg|

# Download... with a user-agent parameter just in case...
# use '--limit-rate=100k' to limit download speed
`wget -c -U "Firefox/4.5.6" -P "#{Output_Directory}" "#{wallp_url}"`
end
end

你需要这两颗宝石。开放uri是标准库的一部分,所以您不需要安装它,但nokogiri不是。按如下方式安装

gem install nokogiri
创建te映射和使用wget进行下载的shell最好用ruby代码代替,如果您搜索一些示例,应该不难,但它们应该在windows中工作。您需要确保wget位于路径中,或者使用命令eg给出路径

`"c:/program files/wget/wget.exe" -c -U "Firefox/4.5.6" -P "#{Output_Directory}" "#{wallp_url}"`  
编辑: 先试试这个

Output_Directory = "c:\temp"
Resolution = "1600x900" 
wallp_url = %|http://wallpaperswide.com/download/#{$1}-#{Resolution}.jpg| 
command = %|"C:/Program Files (x86)/GnuWin32/bin/wget.exe" -c -U "Firefox/4.5.6" -P "#{Output_Directory}" "#{wallp_url}"|
puts command

#=> "C:/Program Files (x86)/GnuWin32/bin/wget.exe" -c -U "Firefox/4.5.6" -P "c:  emp" "http://wallpaperswide.com/download/-1600x900.jpg"
你不应该出错。小心前面的斜杠。 然后,通过将命令粘贴到命令行来运行放在控制台中的命令。 如果出现错误,说明路径或firefox参数有问题。 只有当wget工作时(在c:\temp映射中有图像),脚本才能工作。 在scipt中,您可以像这样运行命令:

`command`
# `wget -c -U "Firefox/4.5.6" -P "#{Output_Directory}" "#{wallp_url}"`
puts "#{wallp_url}"

如果脚本中仍然存在错误,请在此处发布错误。

您能否注释掉代码中的“wget”行,并在其位置放置一条puts语句,如下所示:

`command`
# `wget -c -U "Firefox/4.5.6" -P "#{Output_Directory}" "#{wallp_url}"`
puts "#{wallp_url}"
这将输出生成的URL。理想情况下,每次应该连续吐出10个URL。如果发生这种情况,那么问题肯定是因为您在Windows中安装了wget或使用了它

这段代码中唯一与平台相关的代码是。
在我最新的博客文章中,我已经在

中写了在Windows系统中要遵循的详细过程,我认为你需要开放uri,因为它需要“开放uri”,出于某种奇怪的原因,它被剥离到linux命令中,所以除非你从cygwin运行它,否则它不会工作。我已经替换了行
wget-c-U“Firefox/4.5.6”-p”#{Output_Directory}“{wallp_url}”
带有
“C:\ProgramFiles(x86)\GnuWin32\bin\wget,exe”-C-U“Firefox/4.5.6”-P“{Output_Directory}”{wallp url}”
,但出现相同的错误。请帮助。