Skip to content

Instantly share code, notes, and snippets.

@schmich
Last active February 8, 2022 14:55
Show Gist options
  • Save schmich/243688ea24cdb6ea1c32 to your computer and use it in GitHub Desktop.
Save schmich/243688ea24cdb6ea1c32 to your computer and use it in GitHub Desktop.
Download desktop-resolution wallpapers from http://psiupuxa.com/
# Download desktop-resolution wallpapers from http://psiupuxa.com/
# into the current directory.
require 'nokogiri'
require 'open-uri'
require 'openssl'
require 'uri'
# Disable SSL verification. Ruby SSL cert bundle isn't installed on Windows by default.
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
page = 'http://psiupuxa.com/'
images = []
puts 'Scraping pages for image links.'
while page
puts "Scraping #{page}."
doc = Nokogiri::HTML(open(page))
doc.css('.post a[href*="desktop"]').each do |a|
images << a['href']
end
link = doc.css('.pages-link-active + a.pages-link').first
page = link ? URI.join(page, link['href']) : nil
end
puts "Found #{images.length} images."
puts 'Downloading images.'
count = 0
images.each do |url|
count += 1
local_file = url.split('/').last
print "[#{count}/#{images.length}] "
if File.exist? local_file
puts "Skipping #{local_file}, file exists."
next
else
puts "Downloading #{local_file}."
end
open(url, 'rb') do |image|
open(local_file, 'wb') do |file|
file.write(image.read)
end
end
end
puts 'Fin.'
@schmich
Copy link
Author

schmich commented Jan 19, 2015

Downloads desktop-resolution wallpapers from Psiu Puxa into the current directory.

gem install nokogiri
curl -LO https://gist.github.com/schmich/243688ea24cdb6ea1c32/raw/psiupuxa.rb
ruby psiupuxa.rb

@thom801
Copy link

thom801 commented Feb 13, 2015

This is so rad thanks man.

@schmich
Copy link
Author

schmich commented Mar 2, 2015

👍 Space is awesome.

@cmoel
Copy link

cmoel commented Sep 10, 2015

This is great! Thanks for sharing so I didn't have to write it 😺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment