|
网站添加天气预报代码,但是很多都是超级链接广告,这里提供个无超级链接广告的天气预报代码给大家分享。
简单的ASP采集TOM天气预报的源代码,代码如下:
<%
on error resume next
function weather(city)
DIM Product(5)
content = getHTTPPage("http://tq.tom.com/china/index.html")
cc = split(content," align=center><td><font color=#005FC9>")
'response.write (cc(0))
for each a in cc
a1 = split(a,"</font></td><td>")'a1(0)为城市
if (a1(0)=city) then
'response.write a1(0)&a1(1)
a2 = split(a1(1),"</td><td>")'a2(0)天气,a2(1)最高温度,a2(2)最低温度
Product(0) = city
Product(1) = a2(0)
Product(2) = a2(1)
Product(3) = a2(2)
a3 = split(a2(3),"</td>")
Product(4) = a3(0)
exit for
end if
'response.write a&vbcrlf
next
weather = Product
end function
response.write city&vbcrlf&a2(0)&vbcrlf&a2(1)&vbcrlf&a2(2)&vbcrlf&wind
Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject("adodb"&"."&"stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
Function getHTTPPage(Path)
t = GetBody(Path)
getHTTPPage=BytesToBstr(t,"GB2312")
End function
Function GetBody(url)
on error resume next
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", url, False, "", ""
.Send
GetBody = .ResponseBody
End With
Set Retrieval = Nothing
End Function
a = weather("南宁")'这里是城市名称
response.write "城市:"&a(0)&"<br>"
response.write "天气:"&a(1)&"<br>"
response.write "最低温度:"&a(2)&"<br>"
response.write "最高温度:"&a(3)&"<br>"
response.write "风力:"&a(4)
%>
'以上代码只需制作个独立文件tq.asp,用<!--#include file="tq.asp"-->实现即可。
'这里也要感谢好朋友(惟零)对我的支持!同时,希望这份源代码能为您解决燃眉之急,如需转载请保留版权。
该文章源自[惟零广告]:http://25gx.com/wl2009/New-356.html |
本文地址: https://jiufei.net/bbs/thread-2097-1-1.html
|