Ruby读取天气预报

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#------------------------------------------------  
#--- 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))}

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!