Created
July 13, 2014 17:32
-
-
Save jasonblanchard/2fe19020141eb61cca67 to your computer and use it in GitHub Desktop.
download links from page with mechanize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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