您现在的位置是: 首页 > 气象雷达 气象雷达

天气预报代码大全_简单滚动天气预报代码

tamoadmin 2024-07-17 人已围观

简介1.php获取天气预报的代码2.网页天气预报插件代码3.怎样在Blog里面放上每天的天气预报呢?4.最好的网页天气预报代码(自动定制城市天气)5.flash天气预报代码<iframe width="420" scrolling="no" height="60" frameborder="0" allowtransparency="true" src="://i.tianqi/index.ph

1.php获取天气预报的代码

2.网页天气预报插件代码

3.怎样在Blog里面放上每天的天气预报呢?

4.最好的网页天气预报代码(自动定制城市天气)

5.flash天气预报代码

天气预报代码大全_简单滚动天气预报代码

<iframe width="420" scrolling="no" height="60" frameborder="0" allowtransparency="true" src="://i.tianqi/index.php?c=code&id=12&icon=1&num=5"></iframe>

绝对管用 样式可以调整 有不懂的可以问我

php获取天气预报的代码

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Data.SqlClient;

using System.Net;

using System.IO;

using System.Collections;

/// <summary>

/// Weather 的摘要说明

/// </summary>

public class Weather

{

public Weather()

{

//

// TODO: 在此处添加构造函数逻辑

//

}

public static string ConvertCodeByCity(string City)

{

string Code = "";

switch (City)

{

case "北京":

Code = "110100";

break;

default:

break;

}

return Code;

}

public static ArrayList GetWeather(string code)

{

/*

[0] "北京 "string

[1] "雷阵雨 "string

[2] "9℃" string

[3] "29℃"string

[4] "小于3级"string

*/

string html = "";

try

{

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("://weather.sina.cn/iframe/weather/" + code + "_w.html ");

request.Method = "Get";

//request.Timeout = 1;

request.ContentType = "lication/x--form-urlencoded ";

WebResponse response = request.GetResponse();

Stream s = response.GetResponseStream();

StreamReader sr = new StreamReader(s, System.Text.Encoding.GetEncoding("GB2312"));

html = sr.ReadToEnd();

s.Close();

sr.Close();

}

catch (Exception err)

{

throw new Exception("访问地址出错~~~ ");

}

int count = html.Length;

int starIndex = html.IndexOf("<table ", 0, count);

int endIndex = html.IndexOf("</table>", starIndex, count - starIndex);

html = html.Substring(starIndex, endIndex - starIndex + 8);

//得到城市

int cityStartIndex = html.IndexOf("<b>", 0, html.Length);

int cityEndIndex = html.IndexOf("</b>", 0, html.Length);

string City = html.Substring(cityStartIndex + 3, cityEndIndex - cityStartIndex - 3);

//得到天气

int weatherStartIndex = html.IndexOf("<b>", cityEndIndex);

int weatherEndIndex = html.IndexOf("</b>", weatherStartIndex);

string Weather = html.Substring(weatherStartIndex + 3, weatherEndIndex - weatherStartIndex - 3);

//得到温度

int temperatureStartIndex = html.IndexOf("<b", weatherEndIndex);

int temperatureEndIndex = html.IndexOf("</b>", weatherEndIndex + 3);

string Temperature = html.Substring(temperatureStartIndex + 21, temperatureEndIndex - temperatureStartIndex - 21);

int int1 = Temperature.IndexOf("℃", 0);

int int2 = Temperature.IndexOf("~", 0);

int int3 = Temperature.IndexOf("℃", int2);

string MinTemperature = Temperature.Substring(int2 + 1, int3 - int2);

string MaxTemperature = Temperature.Substring(0, int2 - int1 + 2);

//得到风力

int windforceStartIndex = html.IndexOf("风力:", temperatureEndIndex);

int windforceEndIndex = html.IndexOf("<br>", windforceStartIndex);

string Windforce = html.Substring(windforceStartIndex + 3, windforceEndIndex - windforceStartIndex - 3);

if (Windforce.Contains("小于") && (!Windforce.Contains("等于"))) //判断风力是否含有"小于"或"小于等于"字样将,如果有的话,将其替换为2-

{

//Windforce = Windforce.Replace("小于", "2-");

string strWindforce = Windforce.Substring(2, Windforce.Length - 3);

int minWindforce = Int32.Parse(strWindforce) - 1;

Windforce = Windforce.Replace("小于", minWindforce.ToString() + "-");

}

else if (Windforce.Contains("小于等于"))

{

string strWindforce = Windforce.Substring(4, Windforce.Length - 5);

int minWindforce = Int32.Parse(strWindforce) - 1;

Windforce = Windforce.Replace("小于等于", minWindforce.ToString() + "-");

}

ArrayList al = new ArrayList();

al.Add(City);

al.Add(Weather);

al.Add(MinTemperature);

al.Add(MaxTemperature);

al.Add(Windforce);

return al;

}

}

网页天气预报插件代码

<?php

$URLStyle?=?"://flash.weather.cn/wmaps/xml/%s.xml";

$chinaURL?=?sprintf($URLStyle,?"china");

$chinaStr?=?file_get_contents($chinaURL);

$chinaObj?=?simplexml_load_string($chinaStr);

$chinaObjLen?=?count($chinaObj->city);

echo?"chinaObjLen?=?".$chinaObjLen."\n";

for?($i=0;$i<$chinaObjLen;$i++){

//遍历省一级节点,共37个

$level1?=?$chinaObj->city[$i]["pyName"];

$shengjiURL?=?sprintf($URLStyle,?$level1);

$shengjiStr?=?file_get_contents($shengjiURL);

//echo?$shengjiStr;

$shengjiObj?=?simplexml_load_string($shengjiStr);?

$shengjiObjLen?=?count($shengjiObj->city);

//?echo?$chinaObj->city[$i]["quName"];

//?echo?"?".$shengjiObjLen."\n";

for?($j=0;$j<$shengjiObjLen;$j++){

//遍历市一级节点

$level2?=?$shengjiObj->city[$j]["pyName"];

$shijiURL?=?sprintf($URLStyle,?$level2);

$shijiStr?=?file_get_contents($shijiURL);

//echo?$shijiStr;

$shijiObj?=?simplexml_load_string($shijiStr);?

//直辖市和海南、台湾、钓鱼岛等没有县级节点

if(!$shijiObj){

echo?"WARNNING:?not?exsit?next?level?node.?-?".$level1."-".$shijiURL."\n";

echo?'?"'.$shengjiObj->city[$j]["cityname"].'"?=>?';

echo?$shengjiObj->city[$j]["url"].",\n";

continue;

}

$shijiObjLen?=?count($shijiObj->city);

//echo?$shengjiObj->city[$j]["cityname"]."?";

//echo?$shijiObjLen."\n";

for?($k=0;$k<$shijiObjLen;$k++){

//遍历县一级节点

$xianji_code?=?$shijiObj->city[$k]["url"];

echo?'?"'.$shijiObj->city[$k]["cityname"].'"?=>?';

echo?$shijiObj->city[$k]["url"].",\n";

//echo?$xianji_code."\n";?

}

}

}

//print_r($chinaObj);

>

通过XML接口根节点递归获得全国几千个县以上城市cide code的代码

怎样在Blog里面放上每天的天气预报呢?

不用安装插件,你把下面的代码插入你的网页中就可以了:第一种: 代码: <iframe width="145" height="130" border="0" align="center" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" src="" allowTransparency="true"></iframe> 效果预览: 说明:这种适合于在网页的边栏插入。但一个缺点是,上面的4个城市是既定的,无法改成别的。插入时,选好网页上的位置,直接将左栏的源代码全部拷进去就行了 第二种: 代码: <IFRAME ID='ifm2' WIDTH='189' HEIGHT='190' ALIGN='CENTER' MARGINWIDTH='0' MARGINHEIGHT='0' HSPACE='0' VSPACE='0' FRAMEBORDER='0' SCROLLING='NO' SRC=''></IFRAME> 效果预览: 说明:这种 也适合于在网页的边栏插入。上面的城市可以自定,比如厦门可改成别的。定制的方法是修改我代码中标红的数字,从1开始代表“香港”开始,每个数字都代表一个城市,厦门是287,具体要哪个城市自己找一下罢。 第三种: 代码: <IFRAME ID='ifm2' WIDTH='260' HEIGHT='70' ALIGN='CENTER' MARGINWIDTH='0' MARGINHEIGHT='0' HSPACE='0' VSPACE='0' FRAMEBORDER='0' SCROLLING='NO' src=""></iframe> 效果预览: 说明:这种适合于在网页的头栏插入。上面的城市可以自定,比如 石家庄可改成别的。定制的方法是修改我代码中标红的数字。具体各个城市对照的id表可在此下载:城市名称及ID对照表(请右键点击—>另存为)。 第四种: 代码: <iframe width="469" height="218" border="0" align="center" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" src="厦门" 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=""></IFRAME> 效果预览: 第六种: 代码: <iframe width=160 height=230 frameborder=0 scrolling=NO src=南昌></iframe> 效果预览: 说明:这种适合于在网页的边栏插入。上面的城市可以自定,比如南昌可改成别的。定制的方法是修改我代码中标红的名称。这里比较简单,直接用汉字改就行了。比如是福州的,你就直接把“厦门”改成福州就行很不错哦,你可以试下

qgulqjbsvk62041435102011-10-12 9:09:45

最好的网页天气预报代码(自动定制城市天气)

在添加天气预报之前,你得先添加(自定义面板),然后输入标题,勾选(显示源代码),在空白面板里粘贴如下代码,另外需要注意的是,代码显示可能不是你想要的城市,那么你就需要修改为你的城市的代码。

几段超酷实用的天气预报代码,整理如下:

第一种:

<iframe src=://weather.265/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='://weather.qq/inc/ss258.htm'></IFRAME>

效果: 使用方法:以上显示的是九江的天气预报,你可以改成你自己的,打开页面:://weather.qq,在右边的框中

选择你所在的城市(比如选择南京),然后打开了这个页面:://weather.qq/preend.htm?dc244.htm,然后将网址中的244替换'://weather.qq/inc/ss258.htm'中的258,那么最后显示出来的就是南京的天气预报。

第三种:

<IFRAME ID='ifm2' WIDTH='260' HEIGHT='70' ALIGN='CENTER' MARGINWIDTH='0' MARGINHEIGHT='0' HSPACE='0' VSPACE='0' FRAMEBORDER='0' SCROLLING='NO' src="://news.sina.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=://news.qq/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="://weather.qq/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="://minisite.qq/Weather/news_new.html" allowTransparency="true"></iframe>

效果:

第七种:

以前很流行的一段代码(在Google上搜到的90%都是这一段),现在已经不能用了,特此写出来,以免大家浪费精力:

<iframe width="150" height="240" frameborder="0" scrolling="No" src='://news.qq/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

以下得到其他城市的代码的方法:

baidu搜索一下城市的名称,比如"重庆",然后地址栏中的那个代码就是了这些中文字符如何编码变成%D6%D8%C7%EC这种的。比如得到的网址是:

://.baidu/s?wd=%D6%D8%C7%EC

后面的%D6%D8%C7%EC即是。

现在我给大家推荐一个专门提供天气预报和免费天气预报代码服务的网站:

天气123:中国城市天气预报(://.tianqi123/)

只要复制粘贴该网站提供的代码就可以了。

如下是3款(南京)效果图:

第八种:

<iframe src="://.tianqi123/small_page/chengshi_1189.html" width=160 height=248 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no align=center id=url></iframe>

第九种:

<iframe src="://.tianqi123/small_page/chengshi_1189.html?c0=F9DC68&c1=white&c2=FEFCE0&t1=red&bg=white&w=160&text=no" width=160 height=248 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no align=center id=url></iframe>

第十种:

<iframe src="://.tianqi123/small_page/chengshi_1189.html?c0=red&c1=FF9900&bg=F4FFF4&w=160&h=20&text=yes" width=160 height=21 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no align=center id=url></iframe>

该天气代码高级使用方法:

如果您会HTML语言,您还可以在iframe代码中的url后面加参数,如:

chengshi_321.html?c0=F9DC68&c1=white&c2=FEFCE0&t1=red&bg=white&w=160&h=250&text=no

其中 c0 表示表格第一行背景颜色,c1,c2表示表格其他行间隔的背景颜色,t1表示标题颜色,bg 表示页面北京颜色,w表示表格宽度 h 表示表格高度

当 text=yes 时,将会出现滚动的天气文字,建议您自己调试看看,如:

chengshi_321.html?c0=red&c1=FF9900&bg=F4FFF4&w=160&h=20&text=yes

注意:颜色请不要加 # 符号,如 #FF9900 请写成 FF9900

````我的BLOG教程里面的东西 如果看着很烦琐 欢迎去我的BLOG 仔细研究

flash天气预报代码

这是你想要的天气预报代码,由中央气象台提供数据,最准确最权威的天气预报,能够根据访客不同的IP地址显示不同城市的天气预报

下面是源程序代码:

<iframe src="://.ttyyy/tianqi/tq.html" width="160" height="60" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>

天气预报FLASH代码1-浅色款://aw.awflasher/getweather.swf"</A> width="190" height="200" type="lication/x-shockwe-flash"></embed>