有没有滚动的天气预报代码asp的
类似于这个网站最下面一个的:http://www.tianqi123.com/main/small_page.html?url=http://www.tianqi123.com/tianqi/chengshi_1.html&city_name=北京 问题点数:20、回复次数:3Top
1 楼chloe(明月楼高休独倚)回复于 2006-06-02 09:05:34 得分 0
ZT:
<style type="text/css">
<!--
body {
background-image: url(images/left1.gif);
background-repeat: repeat-y;
font-size: 12px;
}
#temp {
margin-top: 10px;
height: 32px;
width: 32px;
margin-left: 45px;
}
#text {
position: absolute;
margin-top: -32px;
margin-left: 105px;
}
-->
<%
'取得远程网页二进制源代码
Function getBoy(url)
'on error resume next
Set objXml = Server.CreateObject("Microsoft.XmlHttp")
with objXml
.open "get",url,false,"",""
.send
getBoy = .responsebody
end with
getBoy = BytesToBstr(GetBoy,"utf-8")
'response.Write(getBoy)
Set objXml = nothing
end function
'处理二进制流代码
Function BytesToBstr(strBody,CodeBase)
dim objStream
set objStream = Server.CreateObject("Adodb.Stream")
objStream.Type = 1
objStream.Mode =3
objStream.Open
objStream.Write strBody
objStream.Position = 0
objStream.Type = 2
objStream.Charset = CodeBase
BytesToBstr = objStream.ReadText
objStream.Close
set objStream = nothing
End Function
%>
<%
'http://weather.china.com.cn/只支持utf-8编码。可恶~~
'传过来汉字,如"上海",不允许输入"上海市"
'对于http://weather.china.com.cn/没有的城市,一律算上海的天气处理
'取的是24小时有效天气。如需取72小时的请更换连接地址即可
sub GetWeather(city)
if len(city)=0 then city=secity(session("city"))
if right(city,1)="市" then city=left(city,len(city)-1)
dim str'存放返回的源码
dim PointCity'城市所在位置
dim tmp1,tmp2'2个数字之间的字符串就是信息的位置
dim temp'调试用的变量
dim PicName'天气对应图片名
dim arr(3)'存放最后的数据
'arr(0)存放图片名
'arr(1)存放天气情况,如晴阴多云等
'arr(2)存放风向风力,如2-6级
'arr(3)存放温度,如0-100度
dim i'针对直辖市的特殊处理i=2。默认为1
i=1
if city="北京" or city="上海" or city="天津" or city="重庆" or city="香港" or city="澳门" then i=2
'获得天气所在网页并获得源码
str=getBoy("http://weather.china.com.cn/forecast/1-1-1.html")
if instr(1,str,city)<=0 then str=getBoy("http://weather.china.com.cn/forecast/1-5-1.html")
if instr(1,str,city)<=0 then str=getBoy("http://weather.china.com.cn/forecast/1-2-1.html")
if instr(1,str,city)<=0 then str=getBoy("http://weather.china.com.cn/forecast/1-4-1.html")
if instr(1,str,city)<=0 then str=getBoy("http://weather.china.com.cn/forecast/1-7-1.html")
if instr(1,str,city)<=0 then str=getBoy("http://weather.china.com.cn/forecast/1-6-1.html")
if instr(1,str,city)<=0 then str=getBoy("http://weather.china.com.cn/forecast/1-8-1.html")
if instr(1,str,city)<=0 then
city="上海"
str=getBoy("http://weather.china.com.cn/forecast/1-2-1.html")
end if
PointCity=instr(1,str,city)
'response.Write(city & "所在位置" & PointCity & "<br/>")
if i=2 then PointCity=instr(cint(PointCity)+1,str,city)
'response.Write(city & "所在位置" & PointCity & "<br/>")
'开始分析代码
'获得天气情况,如晴
tmp1=instr(cint(PointCity)+1,str,"<td>")
tmp2=instr(tmp1,str,"</td>")
arr(1)=mid(str,cint(tmp1)+4,cint(tmp2)-4-cint(tmp1))
'response.Write("tmp1 " & tmp1 & "tmp2 " & tmp2 & "arr(1) " & arr(1) & "<br/>")
'获得风向风力,如2-6级
tmp1=instr(tmp2,str,"<td>")
tmp2=instr(tmp1,str,"</td>")
arr(2)=mid(str,cint(tmp1)+4,cint(tmp2)-4-cint(tmp1))
'response.Write("tmp1 " & tmp1 & "tmp2 " & tmp2 & "arr(2) " & arr(2) & "<br/>")
'存放温度,如0-100度
tmp1=instr(tmp2,str,"<td>")
tmp2=instr(tmp1,str,"</td>")
arr(3)=mid(str,cint(tmp1)+4,cint(tmp2)-4-cint(tmp1))
'response.Write("tmp1 " & tmp1 & "tmp2 " & tmp2 & "arr(3) " & arr(3) & "<br/>")
'存放第二天的天气情况,如晴.暂时屏蔽
tmp1=instr(tmp2,str,"<td>")
tmp2=instr(tmp1,str,"</td>")
'arr(3)=mid(str,cint(tmp1)+4,cint(tmp2)-4-cint(tmp1))
'response.Write("tmp1 " & tmp1 & "tmp2 " & tmp2 & "arr(3) " & arr(3) & "<br/>")
'存放第二天的风力,如2-6级
tmp1=instr(tmp2,str,"<td>")
tmp2=instr(tmp1,str,"</td>")
'arr(3)=mid(str,cint(tmp1)+4,cint(tmp2)-4-cint(tmp1))
'response.Write("tmp1 " & tmp1 & "tmp2 " & tmp2 & "arr(3) " & arr(3) & "<br/>")
'存放第二天的温度,如0-100度
tmp1=instr(tmp2,str,"<td>")
tmp2=instr(tmp1,str,"</td>")
arr(3)=arr(3) & "~" & mid(str,cint(tmp1)+4,cint(tmp2)-4-cint(tmp1))
'response.Write("tmp1 " & tmp1 & "tmp2 " & tmp2 & "arr(3) " & arr(3) & "<br/>")
'response.Write("<div id='temp'><img src='images/temp/00.gif'></div><div id='text'>晴<br/>19℃~27℃</div>")
'雷雨05.gif尚为标注
Select case arr(1)
case "晴"
PicName="00.gif"
case "多云"
PicName="01.gif"
case "阴"
PicName="02.gif"
case "小雨"
PicName="07.gif"
case "大雪"
PicName="13.gif"
case "雾"
PicName="20.gif"
case "雨夹雪"
PicName="06.gif"
case "小雪"
PicName="14.gif"
case "中雪"
PicName="16.gif"
case "中雨"
PicName="08.gif"
case "大雨"
PicName="09.gif"
case else
PicName="17.gif"
end select
response.Write("<div id='temp'><img src='images/temp/" & PicName & "'></div>")
response.Write("<div id='text'>" & arr(1) & " " & arr(3) & "<br/>" & arr(2) & "</div>")
end sub
%>
</style>
<body topmargin="0" leftmargin="0" style="background-color=transparent">
<%'GetWeather("天津"):response.End()%>
<%
if len(session("city"))=0 then
GetWeather("天津")
'GetWeather(getCNamefromIP("1"))
else
'不给参数则读取session里的变量
GetWeather("")
end if
%>
</body>
Top
2 楼gxh7506(潇湘水云(.NET深圳程序员联盟群:22059542,QQ:78726784))回复于 2006-06-02 09:12:06 得分 0
这类代码有很多,呵呵Top
3 楼baishuijiang5()回复于 2006-11-26 11:49:30 得分 0
markTop




