asp数据采集

数据采集程序

asp数据采集'On Error Resume Next
asp数据采集
Server.Scripttimeout=300
asp数据采集
asp数据采集
'---------------------------------------------------------------------
asp数据采集'
采集数据
asp数据采集
Function getHTTPData(url) 
asp数据采集    
dim http 
asp数据采集    
set http=Server.createobject("Msxml2.XMLHTTP")
asp数据采集    
if instr(url,"http://")=0 then url="http://"&url
asp数据采集    Http.open 
"GET",url,false 
asp数据采集    Http.send() 
asp数据采集    
if Http.Status<>200  then exit function 
asp数据采集    getHTTPData
=bytesToBSTR(Http.responseBody,"UTF-8")
asp数据采集    
set http=nothing
asp数据采集    
if err.number<>0 then err.Clear
asp数据采集    sCharset
="" 
asp数据采集
End function
asp数据采集
'---------------------------------------------------------------------        
asp数据采集
Function BytesToBstr(body,Cset)
asp数据采集    
dim objstream
asp数据采集    
set objstream = Server.CreateObject("adodb.stream")
asp数据采集    objstream.Type 
= 1
asp数据采集    objstream.Mode 
=3
asp数据采集    objstream.Open
asp数据采集    objstream.Write body
asp数据采集    objstream.Position 
= 0
asp数据采集    objstream.Type 
= 2
asp数据采集    objstream.Charset 
= Cset
asp数据采集    BytesToBstr 
= objstream.ReadText 
asp数据采集    objstream.Close
asp数据采集    
set objstream = nothing
asp数据采集
End Function
asp数据采集
'---------------------------------------------------------------------    
asp数据采集'
服务器登录
asp数据采集
Function login(url) 
asp数据采集    
dim http 
asp数据采集    
set http=Server.createobject("Msxml2.XMLHTTP")
asp数据采集    
if instr(url,"http://")=0 then url="http://"&url
asp数据采集    Http.open 
"GET",url,false 
asp数据采集    Http.send() 
asp数据采集    
if Http.Status<>200 then exit function 
asp数据采集    
set http=nothing
asp数据采集    
if err.number<>0 then err.Clear
asp数据采集
End function
asp数据采集
'---------------------------------------------------------------------
asp数据采集'
正则替换
asp数据采集
Function ReplaceText(fString,patrn, replStr)
asp数据采集    
Set regEx = New RegExp
asp数据采集    regEx.Pattern 
= patrn
asp数据采集    regEx.IgnoreCase 
= True
asp数据采集    regEx.Global 
= True
asp数据采集    ReplaceText 
= regEx.Replace(fString, replStr)
asp数据采集
End Function
asp数据采集
'---------------------------------------------------------------------
asp数据采集'
去标签 包括内容
asp数据采集
Function ReplaceTag(str, tag)
asp数据采集    
Set regEx = New RegExp
asp数据采集    regEx.Pattern 
= "<"&tag&"[^>]*?>.*?<\/"&tag&">"
asp数据采集    regEx.IgnoreCase 
= True
asp数据采集    regEx.Global 
= True
asp数据采集    ReplaceTag
=regEx.Replace(str, "")
asp数据采集
End Function
asp数据采集
'---------------------------------------------------------------------    
asp数据采集'
去标签 不包括内容
asp数据采集
Function ReplaceTab(str, tag)
asp数据采集    
Set regEx = New RegExp
asp数据采集    regEx.Pattern 
= "<\/?"&tag&"[^>]*>"
asp数据采集    regEx.IgnoreCase 
= True
asp数据采集    regEx.Global 
= True
asp数据采集    ReplaceTab
=regEx.Replace(str, "")
asp数据采集
End Function
asp数据采集
'---------------------------------------------------------------------    
asp数据采集'
去标签属性 保留标签
asp数据采集
Function ReplaceinnerTag(str, tag)
asp数据采集    
Set regEx = New RegExp
asp数据采集    regEx.Pattern 
= "(<\/?"&tag&")[^>]*>"
asp数据采集    regEx.IgnoreCase 
= True
asp数据采集    regEx.Global 
= True
asp数据采集    ReplaceinnerTag
=regEx.Replace(str, "$1>")
asp数据采集
End Function
asp数据采集
'---------------------------------------------------------------------    
asp数据采集'
按正则取数据
asp数据采集
Function getText(fString, patrn,n) 
asp数据采集    
dim Matches, tStr
asp数据采集    tStr 
= fString
asp数据采集    
Set re = New Regexp
asp数据采集    re.IgnoreCase 
= True
asp数据采集    re.Global 
= True
asp数据采集    re.Pattern 
=  patrn
asp数据采集    
set Matches = re.Execute(tStr)
asp数据采集    
set re = nothing 
asp数据采集    rStr 
= ""
asp数据采集    
For Each Match in Matches
asp数据采集        rStr 
= Match.SubMatches(n)
asp数据采集        
exit for
asp数据采集    
Next
asp数据采集    getText 
= rStr
asp数据采集
End Function
asp数据采集
'---------------------------------------------------------------------
asp数据采集'
数据过滤
asp数据采集
Function Encode_text(str)
asp数据采集    
If Isnull(str) Then
asp数据采集        Encode_text 
= ""
asp数据采集        
Exit Function 
asp数据采集    
End If
asp数据采集    str 
= ReplaceText(str, "<\/?br[^>]*>" , vbCrlf )
asp数据采集    str 
= ReplaceText(str, "<\/?p[^>]*>" , vbCrlf )
asp数据采集    str 
= ReplaceTab(str, "[a-zA-Z]")
asp数据采集    str 
= ReplaceText(str, "\n\s*\r" ,Chr(10)&Chr(13))
asp数据采集    str 
= Replace(str, "&" , "&amp;" )
asp数据采集    str 
= Replace(str, ";" , ";" )
asp数据采集    str 
= Replace(str, "&amp;" , "&amp;" )
asp数据采集    str 
= Replace(str,Chr(34), "&quot;" )
asp数据采集    str 
= Replace(str, "'" , "'" )
asp数据采集    str 
= Replace(str, "<" , "&lt;" )
asp数据采集    str 
= Replace(str, ">" , "&gt;" )
asp数据采集    str 
= Replace(str, "(" , "(" )
asp数据采集    str 
= Replace(str, ")" , ")" )
asp数据采集    str 
= Replace(str, "*" , "*" )
asp数据采集    str 
= Replace(str, "%" , "%" )
asp数据采集    str 
= Replace(str,vbCrlf, "<br/>" )
asp数据采集    Encode_text 
= str
asp数据采集
End Function
asp数据采集
'---------------------------------------------------------------------
asp数据采集'
通过Matches取数据
asp数据采集
dim Matches
asp数据采集
sub setMatches(str,sRe)
asp数据采集    
Set re = New Regexp
asp数据采集    re.IgnoreCase 
= True
asp数据采集    re.Global 
= True
asp数据采集    re.Pattern 
=  sRe
asp数据采集    
set Matches = re.Execute(str)
asp数据采集    
set re=nothing 
asp数据采集
end sub
asp数据采集
'---------------------------------------------------------------------


例子

asp数据采集'例子
asp数据采集
call setMatches(textcontent, re)
asp数据采集
For Each Match in Matches
asp数据采集    response.write Match.value
asp数据采集
Next

相关文章: