Skip to content

Instantly share code, notes, and snippets.

@nakajijapan
Created May 4, 2012 08:25
Show Gist options
  • Save nakajijapan/2593275 to your computer and use it in GitHub Desktop.
Save nakajijapan/2593275 to your computer and use it in GitHub Desktop.
get female high-school student's image from naver
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
def save_image(url, index)
suffix = 'jpg' if url.index('jpg') || url.index('jpeg')
suffix = 'png' if url.index('png')
suffix = 'gif' if url.index('gif')
open("/tmp/desktop#{index}.#{suffix}", 'wb') do |file|
open(url) do |data|
file.write(data.read)
end
end
end
#url = "http://search.naver.jp/image?q=%E3%81%82%E3%83%BC%E3%82%8A%E3%82%93&sm=sbx_hty.image"
# アーリン
#url = "http://search.naver.jp/image?q=%E4%BD%90%E3%80%85%E6%9C%A8%E5%BD%A9%E5%A4%8F&sm=sbx_sug.image&sme=6"
# jk
url = "http://search.naver.jp/image?q=%E5%A5%B3%E5%AD%90%E9%AB%98%E7%94%9F&sm=sbx_hty.image"
require 'hpricot'
require 'open-uri'
require 'uri'
doc = Hpricot( open(url).read )
list = []
(doc/:img).each do |link|
list.push link[:orgsrc]
end
(0..20).each do |i|
save_image(list[rand(list.length)], i.to_s)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment