class WebkitToPng def self.create(urls, options={}) urls.each do |url| puts "convert #{url} to #{options[:dir]}" url.sub!('//', "//#{options[:auth]}@") if options[:auth] op = "-F -D #{options[:dir]} -o #{url.split('/').last}" op += " --user-agent='#{user_agent}'" if options[:mobile] exec(url, op) end end private def self.exec(url, options) `/Users/hidenba/project/webkit2png/webkit2png #{options} #{url}` end def self.user_agent 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53' end end WebkitToPng.create(new_urls, {auth: auth, mobile: false, dir: './pc_new_url'}) WebkitToPng.create(new_urls, {auth: auth, mobile: false, dir: './pc_old_url'}) WebkitToPng.create(new_urls, {auth: auth, mobile: true, dir: './mobile_new_url'}) WebkitToPng.create(new_urls, {auth: auth, mobile: true, dir: './mobile_old_url'})