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


Copy this code and paste it in your 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

You need to login to post a comment.