读取tq1**里深圳的天气预报,输出html
突然想玩玩erb模板就用多了几行代码。。
结果就不贴图了,就那么几个字,找到好看的天气图片再弄上去
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
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))}
|