Created
October 3, 2019 19:57
-
-
Save pasterp/c0e5389bb1274d038c4d34c157369585 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'httparty' | |
require 'fileutils' | |
require 'open-uri' | |
require 'nokogiri' | |
base_url = "http://www.bonjourmadame.fr" | |
page = "" | |
regex = /<img SRC="(.+)" alt="/i | |
output_dir = Dir.home+'/.bjmadame/' | |
FileUtils.mkdir_p output_dir | |
response = HTTParty.get(base_url+page) | |
if response.code == 200 | |
page = Nokogiri::HTML(response.body) | |
img = page.css('img.alignnone').first | |
url = img['src'] | |
filename = url.split('/').last | |
puts filename | |
File.open(output_dir + filename, "wb" ) do |file| | |
open(url, "rb") do |img| | |
file.write(img.read) | |
end | |
end | |
system("hsetroot -cover #{output_dir + filename}") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment