# Net/HTTP get

**URL:** <https://www.ruby-forum.com/t/net-http-get/159383>\
**Category:** Ruby\
**Created:** [February 4, 2009, 2:47am UTC](https://www.ruby-forum.com/t/net-http-get/159383 "2009-02-04T02:47:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [February 4, 2009, 2:47am UTC](https://www.ruby-forum.com/t/net-http-get/159383/1 "2009-02-04T02:47:38Z")

</div>

doc = Hpricot(open(“[http://redhanded.hobix.com/index.html](http://redhanded.hobix.com/index.html)”))  
images = (doc/“img”)  
count = 0

Net::HTTP.start(“[redhanded.hobix.com](http://redhanded.hobix.com)”) do |http|  
images.each do |img|  
filename = img[‘src’].match(/([^/]+..+)/)  
resp = http.get(“#{img[“src”]}”)  
open(“#{filename[1]}”, “w”) do |file|  
file.write(resp.body)  
end  
count += 1  
end  
end

So thats fairly simple, because images on \_why’s blog are stored as  
such: [redhanded.hobix.com/images/whatever.w/e](http://redhanded.hobix.com/images/whatever.w/e)

But how would I grab an image if it was, say, on [slashdot.com](http://slashdot.com)?  
([images.slashdot.com/image.jpg](http://images.slashdot.com/image.jpg))

With my understanding, doing just an http.get(“images.slashdot.etc.”)  
wouldn’t work, because it bases it off of the .start? Any help is  
appreciated!

---

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [February 4, 2009, 3:26am UTC](https://www.ruby-forum.com/t/net-http-get/159383/2 "2009-02-04T03:26:01Z")

</div>

On Feb 3, 8:47 pm, Tim M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> doc = Hpricot(open(“[http://redhanded.hobix.com/index.html](http://redhanded.hobix.com/index.html)”))  
> images = (doc/“img”)  
> count = 0
> 
> Net::HTTP.start(“[redhanded.hobix.com](http://redhanded.hobix.com)”) do |http|  
> images.each do |img|  
> filename = img[‘src’].match(/([^/]+..+)/)  
> resp = http.get(“#{img[“src”]}”)

If it’s a full URL then you just have to create a uri object:  
http.get(URI.parse(img[‘src’]))

- Mark.
