Posted By

aravet on 11/30/-1


Tagged

textmate html ruby io


Versions (?)

Who likes this?

11 people have marked this snippet as a favorite

jonbaer
sp00nyG
jpb
idiotkings
Tlogmer
Jargon
vali29
webstic
heckfy
kzelda
ringo380


reading html from an external URL


 / Published in: Ruby
 

reference: \n http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html

http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html

  1. #1
  2. response = http.get(\'/index.html\')
  3.  
  4. # using block
  5. File.open(\'result.txt\', \'w\') {|f|
  6. http.get(\'/~foo/\') do |str|
  7. f.write str
  8. end
  9. }
  10.  
  11. #2
  12. res = Net::HTTP.get_response(URI.parse(\'http://www.example.com/index.html\'))
  13. print res.body
  14.  
  15. #3
  16. res = Net::HTTP.get_response(\'www.example.com\', \'/index.html\')
  17. print res.body

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: plexus on June 19, 2007

require 'open-uri'; puts open('http://example.com/').read

See open-uri in the standard lib

You need to login to post a comment.