查看: 18662|回复: 7
打印 上一主题 下一主题

比较实用的8种天气预报的一段流行代码

[复制链接]
跳转到指定楼层
1#
发表于 2007-10-5 16:16:07 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
台州网址导航
第一种:

<iframe src=http://weather.265.com/weather.htm width

="160" height="54" frameborder="no" border="0" marginwidth

="0" marginheight="0" scrolling="no"></iframe>



第二种:


<IFRAME ID=''ifm2'' WIDTH=''189'' HEIGHT=''190'' ALIGN=''CENTER'' MARGINWIDTH

=''0'' MARGINHEIGHT=''0'' HSPACE=''0'' VSPACE=''0'' FRAMEBORDER=''0'' SCROLLING=

''NO'' SRC=''http://weather.qq.com/inc/ss258.htm''></IFRAME>



第三种:


<IFRAME ID=''ifm2'' WIDTH=''260'' HEIGHT=''70'' ALIGN=''CENTER'' MARGINWIDTH

=''0'' MARGINHEIGHT=''0'' HSPACE=''0'' VSPACE=''0'' FRAMEBORDER=''0'' SCROLLING

=''NO'' src="http://news.sina.com.cn/iframe/weather/130101.html"></ifreame>





第四种:


<iframe width="469" height="218" border="0" align="center" marginwidth=

"0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" src

="http://appnews.qq.com/cgi-bin/news_weather_search?city=

厦门
" allowTransparency="true"></iframe>





第五种:


<IFRAME ID=''ifm1'' WIDTH=''405'' HEIGHT=''332'' ALIGN=''center'' MARGINWIDTH

=''0'' MARGINHEIGHT=''0'' HSPACE=''0'' VSPACE=''0'' FRAMEBORDER=''0'' SCROLLING

=''NO'' SRC="http://weather.qq.com/24.htm"></IFRAME>





第六种:


<iframe width="145" height="130" border="0" align="center" marginwidth=

"0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling

="no" src="http://minisite.qq.com/Weather/news_new.html" allowTransparency

="true"></iframe>


第七种

<script language="Javascript" src="http://Weather.love163.com/Site_Auto.Jsp?Purl=0"></script>

详细见演示地址:http://weather.love163.com/Code.html

大家可根据自己的爱好,把代码插入要显示的位置即可。本站采用第二种,虽然颜色不是太协调,但也凑合用吧,另外需要注意一下,以前很流行的一段代码(在Google上搜到的90%都是这一段),现在已经不能用了,特此写出来,以免大家浪费精力:


<iframe width="150" height="240" frameborder="0" scrolling=

"No" src=''http://appnews.qq.com/cgi-bin/news_qq_search?city=xxx''></iframe>

其中的“xxx”是每个城市的代码:比如武汉的就是%CE%E4%BA%BA
下面是其他的一些城市的编码:

   上海-%C9%CF%BA%A3
   北京-%B1%B1%BE%A9
   青岛-%C7%E0%B5%BA
   济南-%BC%C3%C4%CF
   武汉-%CE%E4%BA%BA
   福州-%B8%A3%D6%DD
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享分享 分享淘帖
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
2#
 楼主| 发表于 2007-10-5 16:16:20 | 只看该作者
台州网址导航
代码:
<script language="javascript"
src="http://extern.t7online.com/javascript/teaser_cncn.js">
</script>

说明:
中国其他各省(区)天气的代码只需将上述代码中的 cncn 换成下列字符串:
广东: gudp 福建: fujp 浙江: zhjp 江苏:jsup 安徽: anhp 山东: shdp  
海南: hanp 广西: guxa 贵州: guzp 云南:yunp 四川: sicp 陕西: saxp  
河南: henp 河北: hebp 山西: shxp 内蒙古:nema 辽宁: linp 吉林: jilp  
黑龙江: hljp 湖北: hubp 湖南: hunp 江西:jixp 甘肃: gasp 宁夏: nixa  
青海: qihp 西藏: xiza 新疆: xija
其它国家天气的代码只需将上述代码中的 cncn 换成下列字符串: :
德国:dldl  美国:naus  加拿大:naka  亚洲:asie  欧洲:euro
日本:japn   韩国:skor  朝鲜:nkor
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
3#
 楼主| 发表于 2007-10-5 16:16:39 | 只看该作者
台州网址导航

比较实用又一种天气预报的一段流行代码[续]

<iframe allowtransparency=true name=weather src=http://tianqi.9991.com/o/ scrolling=no frameborder=0 marginwidth=1 marginheight=1 height=70 width=298></iframe>
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
4#
 楼主| 发表于 2007-10-5 16:16:57 | 只看该作者
台州网址导航
程序简介:
本天气预报的数据资源采自网络,代码可以根据页面浏览者的ip智能显示所在地天气预报,也支持由浏览者定制自己的城市天气(具体操作请进入:http://weather.mzoe.com/),显示上用户可以自定义部分参数从而达到使其与自己页面的搭配。

程序演示:

使用说明:[code][/code]在相应的页面插入此代码即可。

其中的frame页面地址后跟的三个参数分别为背景颜色、文字大小、文字颜色,可以配合自己的页面来定义。

相关网站:
天气网(为您提供2401个城区未来五天的天气预报!)
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
5#
 楼主| 发表于 2007-10-5 16:17:09 | 只看该作者
台州网址导航

复制代码
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
6#
 楼主| 发表于 2007-10-5 16:17:25 | 只看该作者
台州网址导航
  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Net;
  7. using System.Text;
  8. using System.IO;
  9. using System.Web;
  10. using System.Web.Services;

  11. namespace WeatherWS
  12. {
  13. ///
  14. /// getCHWeather 的摘要说明。
  15. ///
  16. [WebService(Namespace="http://flying.redv.com/monster")]
  17. public class getCHWeather : System.Web.Services.WebService
  18. {
  19. public getCHWeather()
  20. {
  21. //CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的
  22. InitializeComponent();
  23. }

  24. #region 组件设计器生成的代码

  25. //Web 服务设计器所必需的
  26. private IContainer components = null;

  27. ///
  28. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  29. /// 此方法的内容。
  30. ///
  31. private void InitializeComponent()
  32. {
  33. }

  34. ///
  35. /// 清理所有正在使用的资源。
  36. ///
  37. protected override void Dispose( bool disposing )
  38. {
  39. if(disposing && components != null)
  40. {
  41. components.Dispose();
  42. }
  43. base.Dispose(disposing);
  44. }

  45. #endregion
  46. [WebMethod(Description="中国各城市(县)天气预报获取服务,可接受一字符串参数(可选的查询方式:·国内城市(县)全名·字首拼音缩写·电话区号·邮政编码,如查询徐州的天气情况可输入'徐州'或'xz'作为参数)")]
  47. public weatherDataClass getWeather(string strCity)
  48. {
  49. weatherDataClass _dsWeather = new weatherDataClass();
  50. try
  51. {
  52. const int maxDay=5;
  53. string []time = new string[maxDay];//存储日期,从今天开始算起
  54. string []weather = new string[maxDay];//保存天气情况数据
  55. string []max = new string[maxDay];//保存最高温度数据
  56. string []min = new string[maxDay];//保存最低温度数据
  57. string []wind = new string[maxDay];//保存风向数据

  58. //发送一个post请求到index.jsp页面以获取城市数据
  59. Uri uri = new Uri("http://www.weathercn.com/forecastn/forcast/index.jsp?searchname="+System.Web.HttpUtility.UrlEncode(strCity,System.Text.Encoding.GetEncoding("GB2312")));
  60. WebRequest wreq=WebRequest.Create(uri);
  61.    
  62. HttpWebResponse wresp=(HttpWebResponse)wreq.GetResponse();
  63.    
  64. string HTML ="";

  65. Stream s=wresp.GetResponseStream();
  66.    
  67. StreamReader objReader = new StreamReader(s,System.Text.Encoding.GetEncoding("GB2312"));
  68. HTML=objReader.ReadToEnd();
  69. if(HTML==null||HTML=="")
  70. return _dsWeather;

  71. HTML = HTML.ToLower();//全部转换为小写
  72. if(HTML==null||HTML=="")
  73. return _dsWeather;
  74. int head,tail,i;
  75. //查找城市数据 如果没有找到 则返回一个空的dataset
  76. head = HTML.IndexOf("查询结果:",0);
  77. head = HTML.IndexOf("station_name=",head);
  78. if(head==-1)
  79. {
  80. return _dsWeather;
  81. }
  82. head = HTML.IndexOf("station_name=",head+1);
  83. tail = HTML.IndexOf("'",head);
  84. string strCityData = HTML.Substring(head,tail-head);//城市数据获取
  85. string href = "http://www.weathercn.com/forecastn/forcast/forecastDetail.jsp?"+strCityData;
  86. //根据城市数据去查询天气情况

  87. wreq=WebRequest.Create(href);
  88. wresp=(HttpWebResponse)wreq.GetResponse();
  89.    
  90. HTML ="";
  91. s=wresp.GetResponseStream();
  92.    
  93. objReader = new StreamReader(s,System.Text.Encoding.GetEncoding("GB2312"));
  94. HTML=objReader.ReadToEnd();
  95. if(HTML==null||HTML=="")
  96. return _dsWeather;
  97. HTML = HTML.ToLower();//全部转换为小写

  98. DateTime dtNow = new DateTime();
  99. dtNow = DateTime.Today;//获取系统当前日期
  100. dtNow = dtNow.Subtract(TimeSpan.Parse("1"));
  101. for(i=0;i<maxDay;i++)
  102. {
  103. dtNow = dtNow.Add(TimeSpan.Parse("1"));
  104. time[i] = dtNow.ToShortDateString();//日期数据
  105. }

  106. //获取天气情况数据,总共maxDay天的数据
  107. String date = DateTime.Now.Year.ToString()+"年"+DateTime.Now.Month.ToString()+"月";//当前年月
  108. head = HTML.IndexOf(date,0);
  109. head = HTML.IndexOf("",head);
  110. for(i=0;i<maxDay;i++)
  111. {
  112. head = HTML.IndexOf("<td",head);
  113. head = HTML.IndexOf("<img",head);
  114. head = HTML.IndexOf("/",head);
  115. head = HTML.IndexOf("/",head+1);
  116. tail = HTML.IndexOf("_",head);
  117. weather[i] = HTML.Substring(head+1,tail-head-1);
  118. head = HTML.IndexOf("",head);
  119. }

  120. //获取近maxDay天温度数据,包括最高温度和最低温度
  121. for(i=0;i<maxDay;i++)
  122. {
  123. head = HTML.IndexOf("max",head);
  124. head = HTML.IndexOf(">",head);
  125. tail = HTML.IndexOf("<",head);
  126. max[i] = HTML.Substring(head+1,tail-head-1);//最高温度

  127. head = HTML.IndexOf("min",head);
  128. head = HTML.IndexOf(">",head);
  129. tail = HTML.IndexOf("<",head);
  130. min[i] = HTML.Substring(head+1,tail-head-1);//最低温度
  131. }

  132. //最近maxDay天的风向数据
  133. head = HTML.IndexOf("<tr",head);
  134. for(i=0;i<maxDay;i++)
  135. {
  136. head = HTML.IndexOf("class",head);
  137. head = HTML.IndexOf(">",head);
  138. tail = HTML.IndexOf("<",head);
  139. wind[i] = HTML.Substring(head+1,tail-head-1);//风向数据
  140. }

  141. //将数据填充到DataSet中去
  142. DataTable dtWeather = new DataTable();
  143. dtWeather.Columns.Add("日期");
  144. dtWeather.Columns.Add("天气");
  145. dtWeather.Columns.Add("最高温度");
  146. dtWeather.Columns.Add("最低温度");
  147. dtWeather.Columns.Add("风力风向");
  148. for(i=0;i<maxDay;i++)
  149. {
  150. DataRow drWeather = dtWeather.NewRow();
  151. drWeather["日期"] = time[i];
  152. drWeather["天气"] = weather[i];
  153. drWeather["最高温度"] = max[i];
  154. drWeather["最低温度"] = min[i];
  155. drWeather["风力风向"] = wind[i];
  156. dtWeather.Rows.Add(drWeather);
  157. }
  158. _dsWeather.dsWeather = new DataSet("weather");
  159. _dsWeather.dsWeather.Tables.Add(dtWeather);
  160. _dsWeather.dsWeather.AcceptChanges();
  161. //开始获取其它数据
  162. //城市具体位置
  163. /*
  164. head = HTML.IndexOf("120小时天气预报",0);
  165. head = HTML.IndexOf("<td",head);
  166. head = HTML.IndexOf(">",head);
  167. tail = HTML.IndexOf("<",head);
  168. //_dsWeather.cityDetail = HTML.Substring(head+1,tail-head-1);
  169. head = HTML.IndexOf(">",tail);
  170. tail = HTML.IndexOf("<",head);
  171. //_dsWeather.cityDetail += HTML.Substring(head+1,tail-head-1);
  172. //电话区号以及邮政编码
  173. head = HTML.IndexOf("",tail);
  174. tail = HTML.IndexOf("",head);
  175. //_dsWeather.tel = HTML.Substring(head+3,tail-head-3);
  176. //邮编
  177. head = HTML.IndexOf("",tail);
  178. tail = HTML.IndexOf("",head);
  179. //_dsWeather.zip = HTML.Substring(head+3,tail-head-3);
  180. */
  181. //城市简介:
  182. head = HTML.IndexOf("城市简介:",0);
  183. tail = HTML.IndexOf("",head);
  184. _dsWeather.cityDes = HTML.Substring(head+5,tail-head-5);

  185. return _dsWeather;

  186. }
  187. catch(Exception e)
  188. {
  189. //DO Something
  190. return _dsWeather;
  191. }
  192. }
  193. //该类用于保存天气数据
  194. public class weatherDataClass
  195. {
  196. public weatherDataClass()
  197. {
  198. tel = zip = cityDetail = cityDes = liveDes = deaDes ="";
  199. }
  200. public DataSet dsWeather;//天气数据
  201. public string tel;//电话区号
  202. public string zip;//邮政编码
  203. public string cityDetail;//城市具体位置
  204. public string cityDes;//城市介绍
  205. public string liveDes;//生活指数
  206. public string deaDes;//疾病指数
  207. }
  208. }
  209. }
复制代码
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
7#
发表于 2008-6-26 10:19:28 | 只看该作者
台州网址导航

发个很不错的天气预报调用代码,雅虎的

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>天气预报</title>
</head>
<style type="text/css">
<!--
body{
         margin-left: 0px;
         margin-top: 0px;
         margin-right: 0px;
         margin-bottom: 0px;
}
-->
</style>
<div style="position:absolute; width:200px; height:38px; z-index:1; left: 0; top: 0;"><img src="Transparent.gif"  width="200" height="38"></div>
<iframe src="http://weather.cn.yahoo.com/cframe.html?city=台州" width="200" height="38" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" name="I1"></iframe>
</body>
</html>

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
8#
发表于 2008-6-26 10:30:58 | 只看该作者
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

网站推广
关于我们
  • 台州朗动科技(Tzweb.com)拥有多年开发网站平台系统门户手机客户端等业务的成功经验。主要从事:政企网站,系统平台,微信公众号,各类小程序,手机APP客户端,浙里办微应用,浙政钉微应用、主机域名、虚拟空间、后期维护等服务,满足不同企业公司的需求,是台州地区领先的网络技术服务商!

Hi,扫描关注我

Copyright © 2005-2026 站长论坛 All rights reserved

Powered by 站长论坛 with TZWEB Update Techonolgy Support

快速回复 返回顶部 返回列表