Andy_P1
(Andy P.)
8 July 2009 09:52
1
Hello !
I'm trying to get a web page width open-uri width this code :
require 'open-uri'
open("http://www.google.com ") {|src|
open("test.htm","wb") {|dst|
dst.write(src.read)
}
}
But it returns me :
cannot convert File into String
src should be a Tempfile.
I think there is an other method called open, what is the full name of
the open uri method ? How could I do ?
Thanks.
···
--
Posted via http://www.ruby-forum.com/ .
Andy
Pasted the code directly into irb and it worked perfectly.
Andrew Timberlake
http://ramblingsonrails.com
http://MyMvelope.com - The SIMPLE way to manage your savings
···
On Wed, Jul 8, 2009 at 11:52 AM, Andy P.<andycootlapin@hotmail.fr> wrote:
require 'open-uri'
open("http://www.google.com ") {|src|
open("test.htm","wb") {|dst|
dst.write(src.read)
}
}
Hello !
I'm trying to get a web page width open-uri width this code :
require 'open-uri'
open("http://www.google.com ") {|src|
open("test.htm","wb") {|dst|
You're looking for the class method in File:
File.open("test.htm","wb") {|dst|
···
At 2009-07-08 05:52AM, "Andy P." wrote:
dst.write(src.read)
}
}
--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
Andy_P1
(Andy P.)
8 July 2009 19:12
4
Glenn Jackman wrote:
Hello !
I'm trying to get a web page width open-uri width this code :
require 'open-uri'
open("http://www.google.com ") {|src|
open("test.htm","wb") {|dst|
You're looking for the class method in File:
File.open("test.htm","wb") {|dst|
Yes but it don't work with :
open("www.google.com") {|src|
I'm not trying that in irb, I imported all the files of uri, open-uri,
but it don't work. What is the full name of the open uri method who
creates a TempFile ?
Must I import other files ?
Thanks.
···
At 2009-07-08 05:52AM, "Andy P." wrote:
--
Posted via http://www.ruby-forum.com/\ .
Can you show specific code and errors? As for Andrew, this worked for
me out of the box:
09:26:33 Temp$ irb19
Ruby version 1.9.1
irb(main):001:0> require 'open-uri'
=> true
irb(main):002:0> open("http://www.google.com ") {|src|
irb(main):003:1* open("test.htm","wb") {|dst|
irb(main):004:2* dst.write(src.read)
irb(main):005:2> }
irb(main):006:1> }
=> 5337
irb(main):007:0> exit
09:26:54 Temp$ wc test.htm
9 190 5337 test.htm
09:27:02 Temp$
Kind regards
robert
···
2009/7/8 Andy P. <andycootlapin@hotmail.fr>:
Glenn Jackman wrote:
At 2009-07-08 05:52AM, "Andy P." wrote:
Hello !
I'm trying to get a web page width open-uri width this code :
require 'open-uri'
open("http://www.google.com ") {|src|
open("test.htm","wb") {|dst|
You're looking for the class method in File:
File\.open\("test\.htm","wb"\) \{|dst|
Yes but it don't work with :
open("www.google.com") {|src|
I'm not trying that in irb, I imported all the files of uri, open-uri,
but it don't work. What is the full name of the open uri method who
creates a TempFile ?
Must I import other files ?
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
Andy_P1
(Andy P.)
26 July 2009 19:50
6
Robert Klemme wrote:
You're looking for the class method in File:
Must I import other files ?
Can you show specific code and errors? As for Andrew, this worked for
me out of the box:
09:26:33 Temp$ irb19
Ruby version 1.9.1
irb(main):001:0> require 'open-uri'
=> true
irb(main):002:0> open("http://www.google.com ") {|src|
irb(main):003:1* open("test.htm","wb") {|dst|
irb(main):004:2* dst.write(src.read)
irb(main):005:2> }
irb(main):006:1> }
=> 5337
irb(main):007:0> exit
09:26:54 Temp$ wc test.htm
9 190 5337 test.htm
09:27:02 Temp$
Kind regards
robert
Sorry for the delay.
Yes, it works !
Now, I would want to download an image file using sockets.
require 'socket'
host = "www.google.fr"
port = 80
path = "/intl/fr_fr/images/logo.gif" #google logo
request = "GET #{path} GIF\r\n\r\n"
socket = TCPSocket.open(host, port)
socket.print(request)
response = socket.read
img = response.split("\r\n\r\n", 2)
puts img
It doesn't works : it returns :
"HTTP/1.1 400 Bad Request"
How to do ?
···
2009/7/8 Andy P. <andycootlapin@hotmail.fr>:
--
Posted via http://www.ruby-forum.com/\ .
7stud
(7stud --)
26 July 2009 22:56
7
request = "GET #{path} GIF\r\n\r\n"
It doesn't works : it returns :
"HTTP/1.1 400 Bad Request"
How to do ?
http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html
···
--
Posted via http://www.ruby-forum.com/\ .
Andy_P1
(Andy P.)
27 July 2009 08:20
8
7stud -- wrote:
request = "GET #{path} GIF\r\n\r\n"
It doesn't works : it returns :
"HTTP/1.1 400 Bad Request"
How to do ?
http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html
Yes it works, thanks all !
···
--
Posted via http://www.ruby-forum.com/\ .