日期:2010-03-28  浏览次数:21181 次

使用说明:

提交城市名参数即可: weather.asp?city=北京

以下是weather.asp源代码:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
on error resume next
dim fcity
fcity=trim(request("city"))
if fcity="" then
fcity = server.urlencode("北京")
end if
Function GetURL(url) 
Set Retrieval = CreateObject("Microsoft.XMLHTTP") 
With Retrieval
.Open "GET", url, False
.Send 
GetURL = bytes2bstr(.responsebody)
if len(.responsebody)<100 then
response.write "获取天气 <a href="&url&" target=_blank>"&url&"</a> 失败。"
response.end
end if
End With 
Set Retrieval = Nothing 
End Function
function bytes2bstr(vin) 
strreturn = "" 
for i = 1 to lenb(vin) 
thischarcode = ascb(midb(vin,i,1)) 
if thischarcode < &h80 then 
strreturn = strreturn & chr(thischarcode) 
else 
nextcharcode = ascb(midb(vin,i+1,1)) 
strreturn = strreturn & chr(clng(thischarcode) * &h100 + cint(nextcharcode)) 
i = i + 1 
end if 
next 
bytes2bstr = strreturn 
end function 
Function ReadTextarea(HTMLstr)
 Set ra = New RegExp
 ra.IgnoreCase = True
 ra.Global = True
 ra.Pattern = ".{0,}<TEXTAREA[^>]+>([.\r\n\s\t]+?)<\/TEXTAREA>.{0,}"
 ReadTextarea = ra.replace(HTMLstr,"$1")
END Function
Function GetKey(HTML,Start,Last)
filearray=split(HTML,Start)
filearray2=split(filearray(1),Last)
GetKey=filearray2(0)
End Function
dim htmlstr
dim w_date,w_pic1,w_pic2,w_m1,w_m2,w_m3
htmlstr = GetURL("http://weather.tq121.com.cn/mapanel/index1.php?city="&fcity&"")
w_date = GetKey(htmlstr,"<span class=""big-cn"">","</span>")
w_pic1 = GetKey(htmlstr,"<td width=""70"" valign=""top""><img src=""../images/",""" width=")
w_pic2 = GetKey(htmlstr,"<td width=""82"" valign=""top""><img src=""../images/",""" width=")
w_m1 =  GetKey(htmlstr,"<td width=""160"" align=""center"" valign=""top"" class=""weather"">","</td>")
w_m2 =  GetKey(htmlstr,"<td width=""160"" align=""center"" valign=""top"" class=""weatheren"">","</td>")
w_m3 =  GetKey(htmlstr,"<td width=""153"" valign=""top""><span class=""big-cn"">","</span>")
Response.CharSet = "GB2312"
Response.Write "<table width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""0"">"
Response.Write "<tr>"
Response.Write " <td width=""45%"" style=""text-align:center;""><img src=""images/"&w_pic1&""" width=""70"" "
Response.Write "height=""65"" /><div style=""text-align:center;"">"&w_m1&"</div></td&g