Reid Thompson
2009-Feb-24 15:19 UTC
[Mechanize-users] need guidance on following links to download files
The script below is a mod of one i found via google. I''m trying to
figure out what i''m missing in order to download the files associated
with the links.
require ''mechanize''
agent = WWW::Mechanize.new
pagent = WWW::Mechanize.new
agent.get("http://www.daytrotter.com/songs?offset=60/")
links = agent.page.search(''a'')
hrefs = links.map { |m| m[''href''] }.select { |u| u =~
/\.mp3.link$/ } #
just links ending in mfile
#puts hrefs
#FileUtils.mkdir_p(''daytrotter'') # keep it neat
hrefs.each { |mfile|
if mfile.match(/^\/download/) then next end
#puts mfile
filename = "#{mfile.split(''/'')[-1]}"
filename.gsub!(''.link'','''')
puts "Saving #{mfile} as #{filename}"
agent.get(mfile).save_as(filename)
}
This results in output of the following format:
Saving
http://daytrotter.com/file_download/76/TwoGallants_DaytrotterSession_2.mp3.link
as TwoGallants_DaytrotterSession_2.mp3
I can''t seem to get the final result to resolve to the actual file...
I''d appreciate any pointers.
Thanks,
reid