asp小偷函数

1.读取网页源代码 一

ASP/Visual Basic代码
  1. '==================================================   
  2. '函数名:GetHttpPage 自动获取编码类型   
  3. '作  用:获取网页源码   
  4. '参  数:HttpUrl ——网页地址   
  5. '==================================================   
  6. Function getHTTPPage(HttpUrl)    
  7.    If IsNull(HttpUrl)=True Then  
  8.       response.Write("请输入网址!")   
  9.       Exit Function  
  10.    End If  
  11.    On Error Resume Next  
  12.     const TimeInterval=3 '设定时间间隔   
  13.     const lResolve=5 '解析域名超时时间,秒   
  14.     const lConnect=5 '连接站点超时时间,秒   
  15.     const lSend=5 '发送数据请求超时时间,秒   
  16.     const lReceive=15 '下载数据超时时间,秒   
  17.    Dim Http   
  18.    Set Http=server.createobject("MSX""ML2.XML""HTTP")   
  19.    http.setTimeouts lResolve*1000,lConnect*1000,lSend*1000,lReceive*1000   
  20.    Http.open "GET",HttpUrl,False  
  21.    http.setRequestHeader "User-Agent","Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)"  
  22.     http.setRequestHeader "Pragma","no-cache"  
  23.     http.setRequestHeader "Cache-Control","no-cache"  
  24.     http.setRequestHeader "Connection","close"  
  25.     On Error Resume Next  
  26.    Http.Send()   
  27.     
  28.     Select Case http.readyState   
  29.         Case 0   
  30.         GetHttpPage="初始化失败"  
  31.         Err.Clear   
  32.         set http=nothing   
  33.         Exit Function  
  34.         Case 1   
  35.         GetHttpPage="连接站点超时"  
  36.         Err.Clear   
  37.         set http=nothing   
  38.         Exit Function  
  39.         Case 2   
  40.         GetHttpPage="服务器故障"  
  41.         Err.Clear   
  42.         set http=nothing   
  43.         Exit Function  
  44.         Case 3   
  45.         GetHttpPage="数据下载超时"  
  46.         Err.Clear   
  47.         set http=nothing   
  48.         Exit Function  
  49.         Case 4   
  50.         '下载成功   
  51.     End Select  
  52.     
  53.     If http.status<>200  then   
  54.     GetHttpPage="下载失败"&http.status""  
  55.     Err.Clear   
  56.     set http=nothing   
  57.     Exit Function  
  58.     END IF          
  59.     
  60.        if InStr(bytesToBSTR(Http.responseBody,"UTF-8"),"charset=")=0 then   
  61.        GetHTTPPage=bytesToBSTR(Http.responseBody,"gb2312")    
  62.         set http=nothing   
  63.        else   
  64.            if left(split(bytesToBSTR(Http.responseBody,"UTF-8"),"charset=")(1),6)="gb2312" or left(split(bytesToBSTR(Http.responseBody,"UTF-8"),"charset=")(1),6)="GB2312" then   
  65.                GetHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")   
  66.            elseif left(split(bytesToBSTR(Http.responseBody,"UTF-8"),"charset=")(1),3)="gbk" or left(split(bytesToBSTR(Http.responseBody,"UTF-8"),"charset=")(1),3)="GBK" then   
  67.                GetHTTPPage=bytesToBSTR(Http.responseBody,"GBK")   
  68.            elseif left(split(bytesToBSTR(Http.responseBody,"UTF-8"),"charset=")(1),5)="utf-8" or left(split(bytesToBSTR(Http.responseBody,"UTF-8"),"charset=")(1),5)="UTF-8" then   
  69.                GetHTTPPage=bytesToBSTR(Http.responseBody,"UTF-8")   
  70.            else   
  71.                GetHTTPPage=bytesToBSTR(Http.responseBody,"gb2312")   
  72.            end if    
  73.         set http=nothing   
  74.        end if   
  75. End Function  

 

2.转码

ASP/Visual Basic代码
  1. '==================================================   
  2. '函数名:BytesToBstr   
  3. '作  用:将获取的源码转换为中文   
  4. '参  数:Body ——要转换的变量   
  5. '参  数:Cset ——要转换的类型   
  6. '==================================================   
  7. Function BytesToBstr(Body,Cset)   
  8. Dim Objstream   
  9. Set Objstream = Server.CreateObject("adodb.stream")   
  10. objstream.Type = 1   
  11. objstream.Mode =3   
  12. objstream.Open   
  13. objstream.Write body   
  14. objstream.Position = 0   
  15. objstream.Type = 2   
  16. objstream.Charset = Cset   
  17. BytesToBstr = objstream.ReadText    
  18. objstream.Close   
  19. set objstream = nothing   
  20. End Function  

 获取数字:

ASP/Visual Basic代码
  1. '==================================================   
  2. '函数名:getNum(str)   
  3. '作  用:获取数字   
  4. '==================================================   
  5. function getNum(str)    
  6.  dim re    
  7.  set re=new RegExp    
  8.  re.pattern="\D"    
  9.  re.global=true    
  10.  getNum = re.replace(str, "")    
  11.  end function  

 截取函数

ASP/Visual Basic代码
  1. Function GetContent(str,start,last,n)   
  2.     If Instr(lcase(str),lcase(start))>0 and Instr(lcase(str),lcase(last))>0 then   
  3.         select case n   
  4.         case 0  '左右都截取(都取前面)(去处关键字)   
  5.         GetContent=Right(str,Len(str)-Instr(lcase(str),lcase(start))-Len(start)+1)   
  6.         GetContent=Left(GetContent,Instr(lcase(GetContent),lcase(last))-1)   
  7.         case 1  '左右都截取(都取前面)(保留关键字)   
  8.         GetContent=Right(str,Len(str)-Instr(lcase(str),lcase(start))+1)   
  9.         GetContent=Left(GetContent,Instr(lcase(GetContent),lcase(last))+Len(last)-1)   
  10.         case 2  '只往右截取(取前面的)(去除关键字)   
  11.         GetContent=Right(str,Len(str)-Instr(lcase(str),lcase(start))-Len(start)+1)   
  12.         case 3  '只往右截取(取前面的)(包含关键字)   
  13.         GetContent=Right(str,Len(str)-Instr(lcase(str),lcase(start))+1)   
  14.         case 4  '只往左截取(取后面的)(包含关键字)   
  15.         GetContent=Left(str,InstrRev(lcase(str),lcase(start))+Len(start)-1)   
  16.         case 5  '只往左截取(取后面的)(去除关键字)   
  17.         GetContent=Left(str,InstrRev(lcase(str),lcase(start))-1)   
  18.         case 6  '只往左截取(取前面的)(包含关键字)   
  19.         GetContent=Left(str,Instr(lcase(str),lcase(start))+Len(start)-1)   
  20.         case 7  '只往右截取(取后面的)(包含关键字)   
  21.         GetContent=Right(str,Len(str)-InstrRev(lcase(str),lcase(start))+1)   
  22.         case 8  '只往左截取(取前面的)(去除关键字)   
  23.         GetContent=Left(str,Instr(lcase(str),lcase(start))-1)   
  24.         case 9  '只往右截取(取后面的)(包含关键字)   
  25.         GetContent=Right(str,Len(str)-InstrRev(lcase(str),lcase(start)))   
  26.         end select   
  27.     Else  
  28.         GetContent=""  
  29.     End if   
  30. End function  

 

未经允许不得转载:Windy's Blog » asp小偷函数

赞 (0)