Forum: Ruby Net/HTTP get

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
907f29cb608004d2156d5ce88240f09b?d=identicon&s=25 Tim Mcd (zonbi)
on 2009-02-04 02:47
doc = Hpricot(open("http://redhanded.hobix.com/index.html"))
images = (doc/"img")
count = 0

Net::HTTP.start("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

But how would I grab an image if it was, say, on slashdot.com?
(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!
134ea397777886d6f0aa992672a50eaa?d=identicon&s=25 Mark Thomas (Guest)
on 2009-02-04 03:26
(Received via mailing list)
On Feb 3, 8:47 pm, Tim Mcd <tmcdow...@gmail.com> wrote:
> doc = Hpricot(open("http://redhanded.hobix.com/index.html"))
> images = (doc/"img")
> count = 0
>
> Net::HTTP.start("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.
This topic is locked and can not be replied to.