<%'@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <%'Response.CodePage="65001"%> <%'Response.Charset="UTF-8" %> <% Response.Expires = -9999 Response.AddHeader "Pragma","no-cache" Response.AddHeader "cache-ctrol","no-cache" Function GetBody(weburl) Dim ObjXMLHTTP Set ObjXMLHTTP=Server.CreateObject("MSXML2.serverXMLHTTP") ObjXMLHTTP.Open "GET",weburl,False ObjXMLHTTP.send While ObjXMLHTTP.readyState <> 4 ObjXMLHTTP.waitForResponse 10000 Wend GetBody=ObjXMLHTTP.responseBody Set ObjXMLHTTP=Nothing End Function 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 RemoveDiv(strHTML) Dim objRegExp, Match, Matches ,tmpstr Set objRegExp = New Regexp objRegExp.IgnoreCase = True objRegExp.Global = True objRegExp.Pattern = "<div> 天气:.+?</div>" '取闭合的<div></div>> Set Matches = objRegExp.Execute(strHTML) '进行匹配 For Each Match in Matches ' 遍历匹配集合 tmpstr=tmpstr+""+Match.Value Next tmpstr=replace(tmpstr,"<div> 天气:","") tmpstr=replace(tmpstr,"</div>","")+" " objRegExp.Pattern = "<div> 温度:.+?</div>" '取闭合的<div></div>> Set Matches = objRegExp.Execute(strHTML) '进行匹配 For Each Match in Matches ' 遍历匹配集合 tmpstr=tmpstr+"实时温度:"+Match.Value Next tmpstr=replace(tmpstr,"<div> 温度:","") tmpstr=replace(tmpstr,"</div>","")+" " objRegExp.Pattern = "<div> 体感温度:.+?</div>" '取闭合的<div></div>> Set Matches = objRegExp.Execute(strHTML) '进行匹配 For Each Match in Matches ' 遍历匹配集合 tmpstr=tmpstr+"体感温度:"+Match.Value Next tmpstr=replace(tmpstr,"<div> 体感温度:","") tmpstr=replace(tmpstr,"</div>","")+" " objRegExp.Pattern = "<div> 舒适度:.+?</div>" '取闭合的<div></div>> Set Matches = objRegExp.Execute(strHTML) '进行匹配 For Each Match in Matches ' 遍历匹配集合 tmpstr=tmpstr+"舒适度:"+Match.Value Next tmpstr=replace(tmpstr,"<div> 舒适度:","") tmpstr=replace(tmpstr,"</div>","")+" " objRegExp.Pattern = "<div> 风向:.+?</div>" '取闭合的<div></div>> Set Matches = objRegExp.Execute(strHTML) '进行匹配 For Each Match in Matches ' 遍历匹配集合 tmpstr=tmpstr+"实时风向:"+Match.Value Next tmpstr=replace(tmpstr,"<div> 风向:","") tmpstr=replace(tmpstr,"</div>","")+" " objRegExp.Pattern = "<div> 相对湿度:.+?</div>" '取闭合的<div></div>> Set Matches = objRegExp.Execute(strHTML) '进行匹配 For Each Match in Matches ' 遍历匹配集合 tmpstr=tmpstr+"相对湿度:"+Match.Value Next tmpstr=replace(tmpstr,"<div> 相对湿度:","") tmpstr=replace(tmpstr,"</div>","")+" " RemoveDiv=tmpstr Set objRegExp = Nothing set Matches=nothing End Function 'pattern = Pattern.compile("(?s)<div> 温度:(.+?)</div>"); 'matcher = pattern.matcher(svrRtnValue); 'if(matcher.find()) 'responseValue+=" "+(matcher.group().replaceAll("<div> 温度:","").replaceAll("</div>","").replaceAll("\n"," ")); ' '/*pattern = Pattern.compile("(?s)<div> 体感温度:(.+?)</div>"); 'matcher = pattern.matcher(svrRtnValue); 'if(matcher.find()) 'responseValue+=",体感:"+(matcher.group().replaceAll("<div> 体感温度:","").replaceAll("</div>","").replaceAll("\n"," "));*/ ' 'pattern = Pattern.compile("(?s)<div> 舒适度:(.+?)</div>"); 'matcher = pattern.matcher(svrRtnValue); 'if(matcher.find()) 'responseValue+=""+(matcher.group().replaceAll("<div> 舒适度:","").replaceAll("</div>","").replaceAll("\n"," ").replaceAll(",",",")); ' 'pattern = Pattern.compile("(?s)<div> 风向:(.+?)</div>"); 'matcher = pattern.matcher(svrRtnValue); 'if(matcher.find()) 'responseValue+="$"+(matcher.group().replaceAll("<div> 风向:","").replaceAll("</div>","").replaceAll("\n"," ").replaceAll("\t","").replaceAll(" ","")); ' 'pattern = Pattern.compile("(?s)<div> 相对湿度:(.+?)</div>"); 'matcher = pattern.matcher(svrRtnValue); 'if(matcher.find()) 'responseValue+=",相对湿度"+(matcher.group().replaceAll("<div> 相对湿度:","").replaceAll("</div>","").replaceAll("\n"," ")); caiurl="http://wap.weather.gov.cn/forecast/AHA/zhengzhou.html" pcontent=BytesToBstr(GetBody(caiurl),"UTF-8") response.write(RemoveDiv(pcontent)) %>