I’m trying to download af picture with http.get(string), where the string is the url. The string is unknow and changes every day. I got that past covered. If I print the string and paste it into http.get it works fine.
Why doesn’t http.get care for variable string?
require 'net/http'
Net::HTTP.start("apod.nasa.gov") { |http|
resp = http.get("/apod/")
resp.body.each{|line|
if(line =~ /.jpg/)
line.sub!("<a href=","")
line.gsub!("\"","")
resp = http.get(line)
open("pic.jpg", "wb") { |file|
file.write(resp.body)
}
break;
end
}
}
sub with
resp = http.get('/image/1011/cygnusNeb_geissinger1200.jpg')
and it works…
Okay, got it now. The string line should be chomped