Screen Scraping an Image

P

Phrogz

How do you screen scrape an image off of a web page?

You find the URL of the image (possibly resolving a relative URL
against the absolute URL of the page) and then ask the web server to
send you that file over http.
 
V

Vitor Peres

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

Here's a script I found at
http://www.rubynoob.com/articles/2006/8/21/how-to-download-files-with-a-ruby-script

require 'net/http'

Net::HTTP.start("static.flickr.com") { |http|
resp = http.get("/92/218926700_ecedc5fef7_o.jpg")
open("fun.jpg", "wb") { |file|
file.write(resp.body)
}
}
Or maybe shorter:

require 'open-uri'

open('image.jpg', 'wb') {|f| f << open('
http://www.domain.com/image.jpg').read }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top