Skip to content

Instantly share code, notes, and snippets.

@jasonblanchard
Created July 13, 2014 17:32
Show Gist options
  • Select an option

  • Save jasonblanchard/2fe19020141eb61cca67 to your computer and use it in GitHub Desktop.

Select an option

Save jasonblanchard/2fe19020141eb61cca67 to your computer and use it in GitHub Desktop.
download links from page with mechanize
require 'mechanize'
require 'open-uri'
url = 'http://33.33.33.11/nicoleandjason.us/links'
agent = Mechanize.new
page = agent.get(url)
page.links.each_with_index do |link, index|
id = rand(100) * index
image_page = link.click
image_page.search('.field-name-field-instf-image-url').each do |field|
field.css('a').each do |link|
puts link.attributes['href']
File.open("images/#{id}.jpg", 'wb') do |file|
file.write open(link.attributes['href'].to_s).read
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment