比较实用的8种天气预报的一段流行代码
第一种:<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 代码:
<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
比较实用又一种天气预报的一段流行代码[续]
<iframe allowtransparency=true name=weather src=http://tianqi.9991.com/o/ scrolling=no frameborder=0 marginwidth=1 marginheight=1 height=70 width=298></iframe> 程序简介:本天气预报的数据资源采自网络,代码可以根据页面浏览者的ip智能显示所在地天气预报,也支持由浏览者定制自己的城市天气(具体操作请进入:http://weather.mzoe.com/),显示上用户可以自定义部分参数从而达到使其与自己页面的搭配。
程序演示: http://weather.mzoe.com/img/2/26.gif
使用说明:在相应的页面插入此代码即可。
其中的frame页面地址后跟的三个参数分别为背景颜色、文字大小、文字颜色,可以配合自己的页面来定义。
相关网站:
天气网(为您提供2401个城区未来五天的天气预报!)
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Net;
using System.Text;
using System.IO;
using System.Web;
using System.Web.Services;
namespace WeatherWS
{
///
/// getCHWeather 的摘要说明。
///
public class getCHWeather : System.Web.Services.WebService
{
public getCHWeather()
{
//CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的
InitializeComponent();
}
#region 组件设计器生成的代码
//Web 服务设计器所必需的
private IContainer components = null;
///
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///
private void InitializeComponent()
{
}
///
/// 清理所有正在使用的资源。
///
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
public weatherDataClass getWeather(string strCity)
{
weatherDataClass _dsWeather = new weatherDataClass();
try
{
const int maxDay=5;
string []time = new string;//存储日期,从今天开始算起
string []weather = new string;//保存天气情况数据
string []max = new string;//保存最高温度数据
string []min = new string;//保存最低温度数据
string []wind = new string;//保存风向数据
//发送一个post请求到index.jsp页面以获取城市数据
Uri uri = new Uri("http://www.weathercn.com/forecastn/forcast/index.jsp?searchname="+System.Web.HttpUtility.UrlEncode(strCity,System.Text.Encoding.GetEncoding("GB2312")));
WebRequest wreq=WebRequest.Create(uri);
HttpWebResponse wresp=(HttpWebResponse)wreq.GetResponse();
string HTML ="";
Stream s=wresp.GetResponseStream();
StreamReader objReader = new StreamReader(s,System.Text.Encoding.GetEncoding("GB2312"));
HTML=objReader.ReadToEnd();
if(HTML==null||HTML=="")
return _dsWeather;
HTML = HTML.ToLower();//全部转换为小写
if(HTML==null||HTML=="")
return _dsWeather;
int head,tail,i;
//查找城市数据 如果没有找到 则返回一个空的dataset
head = HTML.IndexOf("查询结果:",0);
head = HTML.IndexOf("station_name=",head);
if(head==-1)
{
return _dsWeather;
}
head = HTML.IndexOf("station_name=",head+1);
tail = HTML.IndexOf("'",head);
string strCityData = HTML.Substring(head,tail-head);//城市数据获取
string href = "http://www.weathercn.com/forecastn/forcast/forecastDetail.jsp?"+strCityData;
//根据城市数据去查询天气情况
wreq=WebRequest.Create(href);
wresp=(HttpWebResponse)wreq.GetResponse();
HTML ="";
s=wresp.GetResponseStream();
objReader = new StreamReader(s,System.Text.Encoding.GetEncoding("GB2312"));
HTML=objReader.ReadToEnd();
if(HTML==null||HTML=="")
return _dsWeather;
HTML = HTML.ToLower();//全部转换为小写
DateTime dtNow = new DateTime();
dtNow = DateTime.Today;//获取系统当前日期
dtNow = dtNow.Subtract(TimeSpan.Parse("1"));
for(i=0;i<maxDay;i++)
{
dtNow = dtNow.Add(TimeSpan.Parse("1"));
time = dtNow.ToShortDateString();//日期数据
}
//获取天气情况数据,总共maxDay天的数据
String date = DateTime.Now.Year.ToString()+"年"+DateTime.Now.Month.ToString()+"月";//当前年月
head = HTML.IndexOf(date,0);
head = HTML.IndexOf("",head);
for(i=0;i<maxDay;i++)
{
head = HTML.IndexOf("<td",head);
head = HTML.IndexOf("<img",head);
head = HTML.IndexOf("/",head);
head = HTML.IndexOf("/",head+1);
tail = HTML.IndexOf("_",head);
weather = HTML.Substring(head+1,tail-head-1);
head = HTML.IndexOf("",head);
}
//获取近maxDay天温度数据,包括最高温度和最低温度
for(i=0;i<maxDay;i++)
{
head = HTML.IndexOf("max",head);
head = HTML.IndexOf(">",head);
tail = HTML.IndexOf("<",head);
max = HTML.Substring(head+1,tail-head-1);//最高温度
head = HTML.IndexOf("min",head);
head = HTML.IndexOf(">",head);
tail = HTML.IndexOf("<",head);
min = HTML.Substring(head+1,tail-head-1);//最低温度
}
//最近maxDay天的风向数据
head = HTML.IndexOf("<tr",head);
for(i=0;i<maxDay;i++)
{
head = HTML.IndexOf("class",head);
head = HTML.IndexOf(">",head);
tail = HTML.IndexOf("<",head);
wind = HTML.Substring(head+1,tail-head-1);//风向数据
}
//将数据填充到DataSet中去
DataTable dtWeather = new DataTable();
dtWeather.Columns.Add("日期");
dtWeather.Columns.Add("天气");
dtWeather.Columns.Add("最高温度");
dtWeather.Columns.Add("最低温度");
dtWeather.Columns.Add("风力风向");
for(i=0;i<maxDay;i++)
{
DataRow drWeather = dtWeather.NewRow();
drWeather["日期"] = time;
drWeather["天气"] = weather;
drWeather["最高温度"] = max;
drWeather["最低温度"] = min;
drWeather["风力风向"] = wind;
dtWeather.Rows.Add(drWeather);
}
_dsWeather.dsWeather = new DataSet("weather");
_dsWeather.dsWeather.Tables.Add(dtWeather);
_dsWeather.dsWeather.AcceptChanges();
//开始获取其它数据
//城市具体位置
/*
head = HTML.IndexOf("120小时天气预报",0);
head = HTML.IndexOf("<td",head);
head = HTML.IndexOf(">",head);
tail = HTML.IndexOf("<",head);
//_dsWeather.cityDetail = HTML.Substring(head+1,tail-head-1);
head = HTML.IndexOf(">",tail);
tail = HTML.IndexOf("<",head);
//_dsWeather.cityDetail += HTML.Substring(head+1,tail-head-1);
//电话区号以及邮政编码
head = HTML.IndexOf("",tail);
tail = HTML.IndexOf("",head);
//_dsWeather.tel = HTML.Substring(head+3,tail-head-3);
//邮编
head = HTML.IndexOf("",tail);
tail = HTML.IndexOf("",head);
//_dsWeather.zip = HTML.Substring(head+3,tail-head-3);
*/
//城市简介:
head = HTML.IndexOf("城市简介:",0);
tail = HTML.IndexOf("",head);
_dsWeather.cityDes = HTML.Substring(head+5,tail-head-5);
return _dsWeather;
}
catch(Exception e)
{
//DO Something
return _dsWeather;
}
}
//该类用于保存天气数据
public class weatherDataClass
{
public weatherDataClass()
{
tel = zip = cityDetail = cityDes = liveDes = deaDes ="";
}
public DataSet dsWeather;//天气数据
public string tel;//电话区号
public string zip;//邮政编码
public string cityDetail;//城市具体位置
public string cityDes;//城市介绍
public string liveDes;//生活指数
public string deaDes;//疾病指数
}
}
}
发个很不错的天气预报调用代码,雅虎的
<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> http://weather.cn.yahoo.com/cframe.html
页:
[1]
