# Screen Scraping an Image

**URL:** <https://rubytalk.org/t/screen-scraping-an-image/42712>\
**Category:** ruby-talk\
**Created:** [3 December 2007 21:15 UTC](https://rubytalk.org/t/screen-scraping-an-image/42712 "2007-12-03T21:15:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sean\_Kenney](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@Sean\_Kenney](https://rubytalk.org/u/Sean_Kenney)\
**Post date:** [3 December 2007 21:15 UTC](https://rubytalk.org/t/screen-scraping-an-image/42712/1 "2007-12-03T21:15:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Gavin\_Kistner3](https://avatars.discourse-cdn.com/v4/letter/g/dfb087/32.png) [@Gavin\_Kistner3](https://rubytalk.org/u/Gavin_Kistner3)\
**Post date:** [3 December 2007 21:24 UTC](https://rubytalk.org/t/screen-scraping-an-image/42712/2 "2007-12-03T21:24:59Z")

</div>

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.

> **···**
>
> On Dec 3, 2:10 pm, Sean Kenney \<skenne...@gmail.com\> wrote:
> 
> > How do you screen scrape an image off of a web page?

---

<div class="post-metadata">

**Author:** ![Robert\_Citek](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@Robert\_Citek](https://rubytalk.org/u/Robert_Citek)\
**Post date:** [3 December 2007 22:25 UTC](https://rubytalk.org/t/screen-scraping-an-image/42712/3 "2007-12-03T22:25:18Z")

</div>

I suspect Sean is asking, what's the ruby way of doing a wget?

For example:

wget [http://www.ruby-lang.org/images/logo.gif](http://www.ruby-lang.org/images/logo.gif)

Regards,  
- Robert

> **···**
>
> On Dec 3, 2007 3:24 PM, Phrogz \<phrogz@mac.com\> wrote:
> 
> > On Dec 3, 2:10 pm, Sean Kenney \<skenne...@gmail.com\> wrote:  
> > \> 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.

---

<div class="post-metadata">

**Author:** ![Sean\_Kenney](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@Sean\_Kenney](https://rubytalk.org/u/Sean_Kenney)\
**Post date:** [3 December 2007 22:39 UTC](https://rubytalk.org/t/screen-scraping-an-image/42712/4 "2007-12-03T22:39:59Z")

</div>

Here's a script I found at [http://www.rubynoob.com/articles/2006/8/21/how-to-download-files-with-a-ruby-script](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://static.flickr.com)") { |http|  
&nbsp;&nbsp;resp = http.get("/92/218926700\_ecedc5fef7\_o.jpg")  
&nbsp;&nbsp;open("fun.jpg", "wb") { |file|  
&nbsp;&nbsp;&nbsp;&nbsp;file.write(resp.body)  
&nbsp;&nbsp;&nbsp;}  
}

---

<div class="post-metadata">

**Author:** ![Vitor\_P](https://avatars.discourse-cdn.com/v4/letter/v/b5ac83/32.png) [@Vitor\_P](https://rubytalk.org/u/Vitor_P)\
**Post date:** [5 December 2007 18:25 UTC](https://rubytalk.org/t/screen-scraping-an-image/42712/5 "2007-12-05T18:25:39Z")

</div>

Or maybe shorter:

require 'open-uri'

open('image.jpg', 'wb') {|f| f \<\< open('  
[Website Domain Names, Online Stores & Hosting | Domain.com](http://www.domain.com/image.jpg&#39;%5C)).read }

> **···**
>
> On Dec 3, 2007 8:39 PM, Sean Kenney \<skenney26@gmail.com\> wrote:
> 
> > Here's a script I found at  
> > [http://www.rubynoob.com/articles/2006/8/21/how-to-download-files-with-a-ruby-script](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|  
> > &nbsp;&nbsp;&nbsp;file.write(resp.body)  
> > &nbsp;&nbsp;}  
> > }
