Skip to content

Instantly share code, notes, and snippets.

@lxfontes
Created July 30, 2010 17:29
Show Gist options
  • Save lxfontes/500945 to your computer and use it in GitHub Desktop.
Save lxfontes/500945 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'mechanize'
agent = Mechanize.new
agent.get("http://www.livingelectro.com/index.php?genre=Trance")
links = agent.page.search('a')
#puts links
hrefs = links.map { |m| m['href'] }.select { |u| u =~ /\-mp3/ }
FileUtils.mkdir_p('livingelectro')
hrefs.each { |mp3|
page = agent.post(mp3,"dl"=>"1")
links = page.search('a')
downloadlink = links.map{|m| m['href']}.select{|u| u =~ /\/download\//}
puts "download link #{downloadlink}"
filename = "livingelectro/#{downloadlink[0].split('/')[-1]}"
puts "Saving #{filename}"
agent.get(downloadlink).save_as(filename)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment