问一个问题:关于XmlHttp!!

斯赛 2003-11-19 12:22:12
近日做一了个关于XmLHttp取远端网页的程序!

但是有些空间显示不出来结果,有些可以!

不知道不显示结果的空间限制了什么功能,各位可以帮帮我吗?


可以显示结果的
http://asp.169163.net/user-371267/ShowNcWeather.asp

无法显示结果的:
http://www.tyemyl.com/qsh/ShowNcWeather.asp

源代码如下:
-----------------------------------------------
-----------------------------------------------

<%
'Server.ScriptTimeOut=3
dim temp1,temp2,temp3
call main("http://cn.weather.yahoo.com/CHXX/CHXX0097/index_c.html")
'主处理文件
function main(url)
on error resume next
if isNull(url) or url="0" then ShowError()
dim w1,w2,w3,w4,w5
'分别是今天天气,最高温度,最低温度,风向,风力
'取得网址
w1=getHTTPPage(url)

if w1 = "" or len(w1) < 500 then ShowError()

temp1=instr(w1,"<br><br><span class=sbody>")
temp2=instr(w1,"风力:</td><td class=sbody>")+35
if temp1=0 then showError()
temp1=temp1+26
'取出中间值
w2=mid(w1,temp1,temp2-temp1)
w1=mid(w1,temp1,20)
Temp3=instr(w1,"<")
if Temp3>0 then
w1=mid(w1,1,temp3-1)
end if
'开始取最高温度
Temp1=instr(w2,"最高:")
Temp2=instr(w2,"风力:</td><td class=sbody>")+35
if temp1=0 then showError()
temp1=temp1+36
w3=mid(w2,temp1,temp2-temp1)
w2=mid(w2,temp1,15)
Temp3=instr(w2,"<")
if Temp3>0 then
w2=mid(w2,1,temp3-1)
end if
'开始取最低温度
Temp1=instr(w3,"最低:")
Temp2=instr(w3,"风力:</td><td class=sbody>")+35
if Temp1=0 then showError()
Temp1=Temp1+36
W4=mid(w3,Temp1,Temp2-Temp1)
W3=mid(w3,Temp1,15)
Temp3=instr(W3,"<")
if Temp3>0 then
w3=mid(w3,1,Temp3-1)
end if
'开始取风向
Temp1=instr(w4,"风向:</td><td class=sbody>")
Temp2=instr(w4,"风力:</td><td class=sbody>")+35
if Temp1=0 then showError()
Temp1=Temp1+24
W5=mid(w4,Temp1,Temp2-Temp1)
w4=mid(w4,Temp1,30)
Temp3=instr(w4,"<")
if Temp3>0 then
w4=mid(w4,1,temp3-1)
end if
'开始取风力
Temp1=instr(w5,"风力:</td><td class=sbody>")
if Temp1=0 then showError()
Temp1=Temp1+24
w5=mid(w5,Temp1,30)
Temp3=instr(w5,"<")
if Temp3>0 then
W5=mid(w5,1,Temp3-1)
end if

response.write(w1&",最高温度:"&w2&",最低温度:"&w3&",风向:"&w4&", 风力:"&w5)


end function
'取得网页文件代码函数
function getHTTPPage(url)
dim http
set http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytes2BSTR(Http.responseBody)
set http=nothing
if err.number<>0 then err.Clear
end function


'字节转化成字符串函数
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 ShowError()
Response.write "很抱歉:因系统错误,无法通知天气情况!今天天气情况请访问 <a href=""http://cn.weather.yahoo.com/CHXX/CHXX0097/index_c.html"" target=_blank>这里</a>"
Response.end
end Function %>
...全文
83 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
斯赛 2003-11-19
  • 打赏
  • 举报
回复
真的可以呢!


谢谢你啊!
不过我想知道这是为什么呢?
liangzhg 2003-11-19
  • 打赏
  • 举报
回复
将set http=server.createobject("MSXML2.XMLHTTP")
换成set http=server.createobject("Microsoft.XMLHTTP")试一下,不行那就试服务器将相应的文件删除了。

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧