weather parsing


/ Published in: Rails
Save to your folder(s)



Copy this code and paste it in your HTML
  1. require 'net/http'
  2. require 'rexml/document'
  3.  
  4.  
  5. url = 'http://weather.yahooapis.com/forecastrss?p=RSXX0438&u=c'
  6.  
  7.  
  8. xml_data = Net::HTTP.get_response(URI.parse(url)).body
  9.  
  10.  
  11. doc = REXML::Document.new(xml_data)
  12. titles = []
  13.  
  14. doc.elements.each('rss/channel/item/yweather:condition') do |ele|
  15. print ele.attributes['temp']
  16. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.