Skip to content

Instantly share code, notes, and snippets.

@cptangry
Last active November 30, 2016 10:27
Show Gist options
  • Save cptangry/66dddbe13f67b0251611375ea007537d to your computer and use it in GitHub Desktop.
Save cptangry/66dddbe13f67b0251611375ea007537d to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# coding: utf-8
require 'nokogiri'
require 'mechanize'
xmlfile, xmlpath = ARGV
def download_image(url, index, link_sum, path)
agent = Mechanize.new
puts "İndiriliyor: #{url}"
agent.get(url).save "./#{path}/#{url.split('/').last}.jpg"
puts "#{index + 1}/#{link_sum} dosya indirildi!
#{index + 1} adet dosyanın indirilmesi tamamlandı!"
end
xmldata = Nokogiri::XML(File.open("#{xmlfile}"))
indirme_linkleri = xmldata.xpath("//#{xmlpath}").map {|link| link.text}.to_a
indirme_linkleri.each_with_index do |link, index|
download_image(link, index, indirme_linkleri.size, xmlpath)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment