Skip to content

Instantly share code, notes, and snippets.

@gonglexin
Created September 10, 2014 08:30
Show Gist options
  • Save gonglexin/1f97c832c7a44c7ccf19 to your computer and use it in GitHub Desktop.
Save gonglexin/1f97c832c7a44c7ccf19 to your computer and use it in GitHub Desktop.
require 'nokogiri'
require 'open-uri'
require 'fileutils'
base_uri = 'http://louie.land/wallpapers'
doc = Nokogiri::HTML(open base_uri)
uris = []
doc.css('.grid a').each do |link|
uris << link
end
wallpapers_path = './wallpapers'
FileUtils.mkdir_p wallpapers_path
FileUtils.cd wallpapers_path
def download_wallpaper(uri)
system "wget #{uri}"
end
def get_the_wallpaper(uri)
wallpapers_base_uri = uri['href']
doc = Nokogiri::HTML(open wallpapers_base_uri)
doc.css('table td a').each do |link|
download_wallpaper("#{wallpapers_base_uri}#{link['href']}") if link.content.end_with?('Desktop.jpg')
end
end
threads = []
uris.each do |uri|
threads << Thread.new do
get_the_wallpaper(uri)
end
end
threads.each { |thr| thr.join }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment