给一段ASPVBScript写的远程读取天气预报的程序。源内容是在http://www.t7online.com/上,根据不同的城市代号(该网站自己定义的)得到具体页面。然后对源代码进行一些修改。
很简陋。
该网页为:http://www.beidou7.com/tq.asp
<%
Function wfile(fileName,IsExist,textInfo)
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If IsExist Then
Set Txt = Sys.OpenTextFile(fileName, 2)
Txt.Write(textInfo)
Txt.Close
msg ="恭喜,文件创建成功并保存!"
ElseIf Sys.FileExists(fileName) Then
msg ="抱歉,文件已经存在!"
End If
Set Sys = Nothing
wfile = msg
End Function
%>
<table width="95%" border="0" cellpadding="0" cellspacing="0" class="h">
<tr align="center">
<td><font color="#000000">扬州地区未来3天 天气预报</font></td>
</tr>
<tr align="center" valign="middle">
<td> <%
Function bytes2BSTR(vIn)
dim strReturn
dim i,ThisCharCode,NextCharCode
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 GetWeatherInfo(cityNumber)
on error resume next
set http=Server.createobject("Msxml2.XMLHTTP")
Http.open "GET","http://www.t7online.com/cgi-bin/citydruck?WMO="&cityNumber&"&LANG=cn&TIME=1082108632",false
Http.send()
if Http.readystate<>4 then exit function
temp=bytes2BSTR(Http.responseBody)
set http=nothing
temp=Left(temp,InStr(temp,CHR(10)&"<table width="&""""&"420")-1)'右边的去除了
temp=Left(temp,InStr(temp,"</table")+7)'右边的去除了
temp=Mid(temp,InStr(temp,"<table")+5)
temp=Mid(temp,InStr(temp,"<table"))
temp=Replace(temp,"/daten","http://www.t7online.com/daten")
temp=Replace(temp,"<font face=""夹发砰"" size=""2"">"," ")
temp=Replace(temp,"</font></td>","</td>")
temp=Replace(temp,"#ffffff","#CCCCCC"""&" clsss=""h")
temp=Replace(temp,"<tr ","<tr bgcolor=""#FFFFFF""")
temp=Replace(temp,"border=""1""","border=""0""")
temp=Replace(temp,"cellspacing=""0""","cellspacing=""1""")
GetWeatherInfo=temp
temp=Replace(temp,"<td ","<td Class=""h""")
response.write(wfile("ld.htm",true,temp))
if err.number<>0 then err.Clear
end function
MyNumber=Request("CityNumber")
if MyNumber="" then
MyNumber="58245"
end if
response.write GetWeatherInfo(MyNumber)
%> </td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td align="center" valign="middle"><a href="http://www.beidou7.com">扬州北斗科技有限公司
</a></td>
</tr>
</table>