Get index.htm and read it out

Hi,
I found this code the pragmatic programmers book.
require ‘net/http’

h = Net::HTTP.new(‘www.pragmaticprogrammer.com’, 80)
resp, data = h.get(‘http://www.pragmaticprogrammer.com/index.html’, nil)
if resp.message == “OK"
data.scan(/<img src=”(.*?)"/) { |x| puts x }
end

So I copied this code and tried to execute it with the ruby interpreter. But
it didn’t work. It just displays an errror message “private method scan
called for nil”. Does anyone have a suggestion why this does not work?
Thanks

Hi,

Hi,
I found this code the pragmatic programmers book.
require ‘net/http’

h = Net::HTTP.new(‘www.pragmaticprogrammer.com’, 80)
resp, data = h.get(‘Pragmatic Bookshelf: By Developers, For Developers’, nil)
if resp.message == “OK”
data.scan(/<img src=“(.*?)”/) { |x| puts x }
end

So I copied this code and tried to execute it with the ruby interpreter. But
it didn’t work. It just displays an errror message “private method scan
called for nil”. Does anyone have a suggestion why this does not work?
Thanks

Pasting lines from your email above into irb worked OK for me
here (ruby 1.6.6 (2001-12-26) [i586-mswin32]).

require ‘net/http’
true
h = Net::HTTP.new(‘www.pragmaticprogrammer.com’, 80)
#<Net::HTTP www.pragmaticprogrammer.com:80 open=false>
resp, data = h.get(‘Pragmatic Bookshelf: By Developers, For Developers’, nil)
[#<Net::NetPrivate::HTTPResponse 200>, “ […long string elided…]
resp.message == “OK”
true
data.scan(/<img src=”(.*?)"/) { |x| puts x }
images/title_main.gif
images/dot.gif
images/dot.gif
images/dot.gif
images/aafounders_70.jpg
images/pp_cover_thumb.png
images/ruby_cover_thumb.png
images/dot.gif
images/dot.gif

Perhaps if you try it in IRB it’ll be more clear which part
of the code is failing on your system?

HTH,

Bill

···

From: “Tom Stone” miner@arcor.de

Could it be the failure that i’m using this version?

ruby 1.7.2 (2002-07-02) [i386-mswin32]

“Bill Kelly” billk@cts.com wrote in message
news:023001c28050$003ea640$fa7b1b42@musicbox…

Hi,

From: “Tom Stone” miner@arcor.de

Hi,
I found this code the pragmatic programmers book.
require ‘net/http’

h = Net::HTTP.new(‘www.pragmaticprogrammer.com’, 80)
resp, data = h.get(‘Pragmatic Bookshelf: By Developers, For Developers’, nil)
if resp.message == “OK”
data.scan(/<img src=“(.*?)”/) { |x| puts x }
end

So I copied this code and tried to execute it with the ruby interpreter.
But
it didn’t work. It just displays an errror message “private method scan
called for nil”. Does anyone have a suggestion why this does not work?
Thanks

Pasting lines from your email above into irb worked OK for me
here (ruby 1.6.6 (2001-12-26) [i586-mswin32]).

require ‘net/http’
true
h = Net::HTTP.new(‘www.pragmaticprogrammer.com’, 80)
#<Net::HTTP www.pragmaticprogrammer.com:80 open=false>
resp, data = h.get(‘Pragmatic Bookshelf: By Developers, For Developers’,
nil)
[#<Net::NetPrivate::HTTPResponse 200>, "<!DOCTYPE HTML PUBLIC
"-//W3C//DTD

···

HTML 4.0 Transitional//EN"> […long string elided…]

resp.message == “OK”
true
data.scan(/<img src=“(.*?)”/) { |x| puts x }
images/title_main.gif
images/dot.gif
images/dot.gif
images/dot.gif
images/aafounders_70.jpg
images/pp_cover_thumb.png
images/ruby_cover_thumb.png
images/dot.gif
images/dot.gif

Perhaps if you try it in IRB it’ll be more clear which part
of the code is failing on your system?

HTH,

Bill

Tom Stone wrote:

Could it be the failure that i’m using this version?

ruby 1.7.2 (2002-07-02) [i386-mswin32]

Yes. I get the same error on ruby 1.7.2 (2002-07-13) [i686-linux], but I
think you can get the same data using resp.body.

···


([ Kent Dahl ]/)_ ~ [ http://www.stud.ntnu.no/~kentda/ ]/~
))_student
/(( _d L b_/ NTNU - graduate engineering - 5. year )
( __õ|õ// ) )Industrial economics and technological management(
_
/ö____/ (_engineering.discipline=Computer::Technology)