<%
on erro">

asp制作的天气预报小偷程序

80酷酷网    80kuku.com

  程序|天气预报|小偷程序|天气预报|小偷程序

使用说明:

提交城市名参数即可: 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%"" 
Response.Write "height=""65"" /><div 
Response.Write "<td width=""55%""><table width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""0"">"
Response.Write "<tr>"
Response.Write "<td height=""20"" class=""zi_he"">"&w_date&"</td>"
Response.Write "</tr>"
Response.Write "<tr>"
Response.Write "<td height=""20"" class=""zi33"">"&w_m2&"</td>"
Response.Write "</tr>"
Response.Write "<tr>"
Response.Write "<td height=""20"" class=""zi33"">"&w_m3&"</td>"
Response.Write "</tr>"
Response.Write "</table>"
%>

附上AJAX查询天气预报的相关代码:

以下是weather.js代码:
// JavaScript Document
var xmlhttp=null; 
function createxmlhttp(){
 try { 
 xmlhttp=new ActiveXObject("Msxml2.xmlhttp") ;
 } 
 catch(e) { 
 try { 
 xmlhttp=new ActiveXObject("Microsoft.xmlhttp") ;
 } 
    catch(oc) { 
 xmlhttp=null ;
 } 
 } 
 if ( !xmlhttp && typeof XMLHttpRequest != "undefined" ) { 
 xmlhttp = new XMLHttpRequest();
 }  
 if (!xmlhttp) {
   //alert("您的浏览器不支AJAX!");
 }
}
function ajaxPost(url,reid){ 
 createxmlhttp();
  //getMode
  xmlhttp.open("get",url,true);
  xmlhttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
  xmlhttp.onreadystatechange= function () { checkState(reid); } ; 
  xmlhttp.send(null);


function  checkState(reid){
if (xmlhttp.readyState == 4){
  document.getElementById(reid).innerHTML="正在加载天气信息...";
  if(xmlhttp.status == 200){
   var retext = xmlhttp.responseText;
   document.getElementById(reid).innerHTML=retext;
   }
 }
 else{
  document.getElementById(reid).innerHTML="正在加载天气信息...";
 }
}

以下是index.html代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>天气预报接口小偷程序 - 阿里西西WEB开发,国内最大的WEB开发资源网站</title>
<script type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location=’"+selObj.options[selObj.selectedIndex].value+"’");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>
<body>
<a href="www.alixixi.com"><img src="http://www.alixixi.com/images/alistudio.gif" alt="阿里西西" width="182" height="49" border=0 longdesc="http://www.alixixi.com" /></a>
<br />
<hr />
<span id="weather"></span>
<p>
  <script src="weather.js" language="javascript"></script>
</p>
<form name="form1" id="form1">
  <select name="menu1" >
    <option value="">请选择城市</option>
    <option value="北京">北京</option>
    <option value="上海">上海</option>
    <option value="南宁">南宁</option>
  </select>
  <div>天气预报小偷程序示例</div>
</form>
</body>
</html>

如果需要现成的示例程序,请点击以下链接在本站下载栏目下载:

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: