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


本文转自博客园cloudgamer的博客,原文链接: asp数据采集,如需转载请自行联系原博主。
相关文章
|
2月前
|
SQL 开发框架 .NET
ASP.NET WEB+EntityFramework数据持久化——考核练习库——1、用户管理系统(考点:查询列表、增加、删除)
ASP.NET WEB+EntityFramework数据持久化——考核练习库——1、用户管理系统(考点:查询列表、增加、删除)
67 0
|
6月前
|
SQL 开发框架 监控
|
SQL 开发框架 .NET
在ASP.NET中使用ListView控件对数据进行显示、分页和排序
在ASP.NET中使用ListView控件对数据进行显示、分页和排序
在ASP.NET中使用ListView控件对数据进行显示、分页和排序
|
开发框架 .NET 数据库连接
在ASP.NET中分页显示DataList控件中的数据
在ASP.NET中分页显示DataList控件中的数据
在ASP.NET中分页显示DataList控件中的数据
|
SQL 存储 开发框架
ASP.NET 使用语言集成查询 LINQ进行数据访问
ASP.NET 使用语言集成查询 LINQ进行数据访问
ASP.NET 使用语言集成查询 LINQ进行数据访问
|
开发框架 JSON 前端开发
ASP.NET MVC5----常见的数据注解和验证
ASP.NET MVC5----常见的数据注解和验证
300 0
ASP.NET MVC5----常见的数据注解和验证
|
JSON 开发框架 .NET
ASP.NET Core: 二十. Action的多种数据返回格式处理机制(四)
上一章讲了系统如何将客户端提交的请求数据格式化处理成我们想要的格式并绑定到对应的参数,本章讲一下它的“逆过程”,如何将请求结果按照客户端想要的格式返回去。
412 0
|
开发框架 JSON .NET
ASP.NET Core: 二十. Action的多种数据返回格式处理机制(三)
上一章讲了系统如何将客户端提交的请求数据格式化处理成我们想要的格式并绑定到对应的参数,本章讲一下它的“逆过程”,如何将请求结果按照客户端想要的格式返回去。
230 0
ASP.NET Core: 二十. Action的多种数据返回格式处理机制(三)
|
开发框架 .NET 数据格式
ASP.NET Core: 二十. Action的多种数据返回格式处理机制(二)
上一章讲了系统如何将客户端提交的请求数据格式化处理成我们想要的格式并绑定到对应的参数,本章讲一下它的“逆过程”,如何将请求结果按照客户端想要的格式返回去。
176 0
|
JSON 开发框架 .NET
ASP.NET Core: 二十. Action的多种数据返回格式处理机制(一)
上一章讲了系统如何将客户端提交的请求数据格式化处理成我们想要的格式并绑定到对应的参数,本章讲一下它的“逆过程”,如何将请求结果按照客户端想要的格式返回去。
214 0