asp数据采集

asp数据采集

数据采集程序

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


例子

None.gif'例子
None.gif
call setMatches(textcontent, re)
None.gif
For Each Match in Matches
None.gif    response.write Match.value
None.gif
Next
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值