Skip to content

Instantly share code, notes, and snippets.

@ibanez270dx
Last active August 29, 2015 14:15
Show Gist options
  • Save ibanez270dx/d765f0dd3fac4e7e7815 to your computer and use it in GitHub Desktop.
Save ibanez270dx/d765f0dd3fac4e7e7815 to your computer and use it in GitHub Desktop.
Scrape a title from specifically formatted content then download and rename
require 'nokogiri'
require 'open-uri'
dir = Dir.pwd
url = "some_url"
data = Nokogiri::HTML(open(url))
data.css('a').each do |link|
filename = link['href']
if filename =~ /^BD/
array = filename.split('_')
new_filename = "#{array[0].gsub("%23","#")}_#{array[1].to_i+2}_#{array[2]}"
command = "wget -c -O #{dir}/#{new_filename} #{url}#{filename}"
# puts command
system command
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment