Ruby读取天气预报

读取tq1**里深圳的天气预报,输出html
突然想玩玩erb模板就用多了几行代码。。
结果就不贴图了,就那么几个字,找到好看的天气图片再弄上去

#————————————————
#— You should install rubyful_soup gem first —-
#———————————@ceilwoo——-
require 'open-uri'
weather=open('http://weather.tq121.com.cn/mapanel/index1_new.php?city=%C9%EE%DB%DA')
require 'rubyful_soup'
soup = BeautifulSoup.new(weather.read,:parse_only_these=>'td')
today = “#{Time.now.day}日-#{Time.now.day.next}日”
wt = soup.find(nil,:attrs=>{'class'=>'weather'}).string
temperature = soup.find(nil,:attrs=>{'class'=>'weatheren'}).string
require 'erb'
html= ERB.new %q{

深圳:<%=a%>

<%=b%>

<%=c%>

}
a=today
b=wt
c=temperature
open('weather.html','w'){|File|File.puts(html.result(binding))}

« »

Leave a Reply

{:1:} {:2:} {:3:} {:4:} {:5:} {:6:} {:7:} {:8:} {:9:} {:10:} {:11:} {:12:} {:13:} {:14:} {:15:} {:16:} {:17:} {:18:} {:19:} {:20:} {:c1:} {:c2:} {:c3:} {:c4:} {:c5:} {:c6:} more »