Getting Text and Images From The Web with Ruby
Here I am going to talk about how to get images and text from the web with Ruby.
I have found a lot of useful informaiton on the web but sometimes it’s too hard to get it without some help. To help me out I created two little snips…
To get text:
require 'uri' url = ARGV[0] # for command line input #url = "http://www.codegin.com" # for direct input puts Net::HTTP.get(URI.parse(url))
To get an image and save it to disk:
require 'net/http'
url = ARGV[0]
img = Net::HTTP.get_response(URI.parse(url))
open("temp.jpg", "wb") { |file|
file.write(img.body)
}
puts "done downloading image"
Here you can replace the ARGV[0] with a hard coded link to get this image and save it directly to disk.
Comments
No comments yet.
Leave a comment