Skip to content

Instantly share code, notes, and snippets.

@daisy1754
Last active December 30, 2015 22:18
Show Gist options
  • Save daisy1754/7892810 to your computer and use it in GitHub Desktop.
Save daisy1754/7892810 to your computer and use it in GitHub Desktop.
UIFacesから顔画像をダウンロードする
require "httparty"
require "nokogiri"
response = HTTParty::get('http://uifaces.com/authorized')
doc = Nokogiri::HTML.parse(response.body, nil, nil)
faces = doc.xpath('//*[@id="app"]/div[2]/div/div/div/a')
names = []
faces.each do |face|
name = face.attributes['title'].value.sub('@', '')
url = face.attributes['data-source'].value
sleep(1)
File.open("#{name}.jpg", "w") do |file|
file.write HTTParty.get(url).body
end
names << name
end
p names
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment