本文提供了一套完整的ASP采集功能函数,包含提取地址的原字符,保存远程的文件到本地模拟登录,获取网页源码等功能函数,阿里西西站长推荐收藏!
'=========
'函数名:GetHt
'作 用:获取网页源码
'参 数:HttpUrl ------网页地址
'=========
Function GetHttpPag
If IsNull(Htt
GetHttpPag
Exit Function
End If
Dim Http
Set Http=serve
Http.open "GET",Http
Http.Send(
If Http.Ready
Set Http=Nothi
GetHttpPag
Exit function
End if
GetHTTPPag
GetHTTPPag
Set Http=Nothi
If Err.number
Err.Clear
End If
End Function
'=========
'函数名:Bytes
'作 用:将获取的源码转换
'参 数:Body ------要转换的
'参 数:Cset ------要转换的
'=========
Function BytesToBst
Dim Objstream
Set Objstream = Server.Cre
objstream.
objstream.
objstream.
objstream.
objstream.
objstream.
objstream.
BytesToBst
objstream.
set objstream = nothing
End Function
'=========
'函数名:PostH
'作 用:登录
'=========
Function PostHttpPa
Dim xmlHttp
Dim RetStr
Set xmlHttp = CreateObje
xmlHttp.Op
XmlHTTP.se
xmlHttp.se
xmlHttp.se
xmlHttp.Se
If Err.Number
Set xmlHttp=No
PostHttpPa
Exit Function
End If
PostHttpPa
Set xmlHttp = nothing
End Function
'=========
'函数名:UrlEn
'作 用:转换编码
'=========
Function UrlEncodin
Dim StrReturn,
StrReturn = ""
For Si = 1 To Len(DataSt
ThisChr = Mid(DataSt
If Abs(Asc(Th
Else
End If
Next
UrlEncodin
End Function
'=========
'函数名:GetBo
'作 用:截取字符串
'参 数:ConStr ------将要截取
'参 数:StartStr
'参 数:OverStr ------结束字符
'参 数:IncluL ------是否包含
'参 数:IncluR ------是否包含
'=========
Function GetBody(Co
If ConStr="$F
GetBody="$
Exit Function
End If
Dim ConStrTemp
Dim Start,Over
ConStrTemp
StartStr=L
OverStr=Lc
Start = InStrB(1, ConStrTemp
If Start<=0 then
GetBody="$
Exit Function
Else
If IncluL=Fal
Start=Star
End If
End If
Over=InStr
If Over<=0 Or Over<=Star
GetBody="$
Exit Function
Else
If IncluR=Tru
Over=Over+
End If
End If
GetBody=Mi
End Function
'========= If TempStr="" If TempStr="" '========= If Right(Cons If Left(LCase '========= Set Re = New Regexp '去掉重复图片开始 response. '转换相对图片地址开 '图片替换/保存 For Tempi=0 To Ubound(Tem Randomize '========= Set Re = New Regexp Set Matches=no '去掉重复文件开始 '转换相对地址开始 '替换 '========= '========= Dim Start,Over If Start<=0 Or Start>=Ove ConTemp=Tr '********* '********* '********* '========= '========= '========= objRegExp. ' 遍历匹配集合,并替换 '========= '========= '========= '********* '********* '********* 'response. If Not objFSO.Fol '********* '********* '********* '********* '********* '========= '========= function unhtmllist function unhtmllist function htmllists( function uhtmllists '========= '========= If TempStr="" '=========
'函数名:GetAr
'作 用:提取链接地址,以
'参 数:ConStr ------提取地址
'参 数:StartStr
'参 数:OverStr ------结束字符
'参 数:IncluL ------是否包含
'参 数:IncluR ------是否包含
'=========
Function GetArray(B
If ConStr="$F
GetArray="
Exit Function
End If
Dim TempStr,Te
TempStr=""
Set objRegExp = New Regexp
objRegExp.
objRegExp.
objRegExp.
Set Matches =objRegExp
For Each Match in Matches
TempStr=Te
Next
Set Matches=no
GetArray="
Exit Function
End If
TempStr=Ri
If IncluL=Fal
objRegExp.
TempStr=ob
End if
If IncluR=Fal
objRegExp.
TempStr=ob
End if
Set objRegExp=
Set Matches=no
TempStr=Re
TempStr=Re
TempStr=Re
TempStr=Re
TempStr=Re
GetArray="
Else
GetArray=T
End if
End Function
'函数名:Defin
'作 用:将相对地址转换为
'参 数:Primitiv
'参 数:ConsultU
'=========
Function DefiniteUr
Dim ConTemp,Pr
If PrimitiveU
DefiniteUr
Exit Function
End If
If Left(Lcase
ConsultUrl
End If
ConsultUrl
ConsultUrl
PrimitiveU
If Instr(Cons
If Instr(Righ
Else
End If
Else
ConsultUrl
End If
End If
ConArray=S
DefiniteUr
ElseIf Left(Primi
DefiniteUr
ElseIf Left(Primi
PrimitiveU
If Right(Cons
DefiniteUr
Else
DefiniteUr
End If
ElseIf Left(Primi
Do While Left(Primi
PrimitiveU
Pi=Pi+1
Loop
For Ci=0 to (Ubound(Co
If DefiniteUr
Else
End If
Next
DefiniteUr
Else
If Instr(Prim
PriArray=S
If Instr(PriA
Else
End If
Else
If Instr(Prim
Else
End If
End If
End If
If Left(Defin
DefiniteUr
End if
If DefiniteUr
DefiniteUr
DefiniteUr
Else
DefiniteUr
End If
End Function
'函数名:Repla
'作 用:替换、保存远程图
'参 数:ConStr ------ 要替换的字符串
'参 数:SaveTf ------ 是否保存文件,Fal
'参 数: TistUrl---
'=========
Function ReplaceSav
If ConStr="$F
ReplaceSav
Exit Function
End If
Dim TempStr,Te
Re.IgnoreC
Re.Global = True
Re.Pattern
Set Matches =Re.Execut
For Each Match in Matches
If TempStr<>"
TempStr=Te
Else
TempStr=Ma
End if
Next
If TempStr<>"
TempArray=
TempStr=""
For Tempi=0 To Ubound(Tem
Re.Pattern
Set Matches =Re.Execut
For Each Match in Matches
Next
Next
End if
If TempStr<>"
Re.Pattern
TempStr=Re
End If
Set Matches=no
Set Re=nothing
If TempStr=""
ReplaceSav
Exit function
End if
TempStr=Re
TempStr=Re
TempStr=Re
Dim RemoteFile
DtNow=Now(
'********
If SaveTf=Tru
SavePath=I
If CheckDir(I
End If
End If
TempArray=
TempStr=""
For Tempi=0 To Ubound(Tem
If Instr(Lcas
TempStr=Te
End If
Next
TempStr=Ri
TempArray=
'去掉重复图片结束
发现图片:
"&Repl
")
TempStr=""
For Tempi=0 To Ubound(Tem
TempStr=Te
Next
TempStr=Ri
TempStr=Re
TempArray2
TempStr=""
'转换相对图片地址结
Set Re = New Regexp
Re.IgnoreC
Re.Global = True
'*********
RemoteFile
If RemoteFile
ArrSaveFil
strFileTyp
If strFileTyp
End If
RanNum=Int
strFileNam
Re.Pattern
response.W
保存到本地
If SaveRemote
response.W
"
Else
End If
ElseIf RemoteFile
Re.Pattern
ConStr=Re.
End If
'*********
Next
Set Re=nothing
ReplaceSav
End function
'函数名:Repla
'作 用:解析动画路径
'参 数:ConStr ------ 要替换的字符串
'参 数: TistUrl---
'=========
Function ReplaceSwf
If ConStr="$F
ReplaceSwf
Exit Function
End If
Dim TempStr,Te
Re.IgnoreC
Re.Global = True
Re.Pattern
Set Matches =Re.Execut
For Each Match in Matches
If TempStr<>"
TempStr=Te
Else
TempStr=Ma
End if
Next
If TempStr<>"
TempArray=
TempStr=""
For Tempi=0 To Ubound(Tem
Re.Pattern
Set Matches =Re.Execut
For Each Match in Matches
Next
Next
End if
If TempStr<>"
Re.Pattern
TempStr=Re
End If
If TempStr=""
ReplaceSwf
Exit function
End if
TempStr=Re
TempStr=Re
TempStr=Re
Set Re=nothing
TempArray=
TempStr=""
For Tempi=0 To Ubound(Tem
If Instr(Lcas
TempStr=Te
End If
Next
TempStr=Ri
TempArray=
'去掉重复文件结束
TempStr=""
For Tempi=0 To Ubound(Tem
TempStr=Te
Next
TempStr=Ri
TempStr=Re
TempArray2
TempStr=""
'转换相对地址结束
Set Re = New Regexp
Re.IgnoreC
Re.Global = True
For Tempi=0 To Ubound(Tem
RemoteFile
Re.Pattern
ConStr=Re.
Next
Set Re=nothing
ReplaceSwf
End function
'过程名:SaveR
'作 用:保存远程的文件到
'参 数:LocalFil
'参 数:RemoteFi
'参 数:Referer ------ 远程调用文件(对付防
'=========
Function SaveRemote
SaveRemote
dim Ads,Retrie
Set Retrieval = Server.Cre
With Retrieval
.Open "Get", RemoteFile
if Referer<>"
.Send
If .Readystat
End If
GetRemot
End With
Set Retrieval = Nothing
Set Ads = Server.Cre
With Ads
.Type = 1
.Open
.Write GetRemoteD
.SaveToF
.Cancel(
.Close()
End With
Set Ads=nothin
end Function
'函数名:GetPa
'作 用:获取分页
'=========
Function GetPaing(B
If ConStr="$F
GetPaing="
Exit Function
End If
TempStr=LC
StartStr=L
OverStr=LC
Over=Instr
If Over<=0 Then
GetPaing="
Exit Function
Else
If IncluR=Tru
Over=Over+
End If
End If
TempStr=Mi
Start=Inst
If IncluL=Fal
Start=Star
End If
GetPaing="
Exit Function
End If
ConTemp=Mi
'ConTemp=R
ConTemp=Re
ConTemp=Re
ConTemp=Re
ConTemp=Re
ConTemp=Re
ConTemp=Re
GetPaing=C
End Function
'函数名:gotTo
'作 用:截字符串,汉字一
'参 数:str ----原字符串
' strlen ----截取长度
'返回值:截取后的字
'*********
function gotTopic(s
if str="" then
gotTopic
exit function
end if
dim l,t,c, i
str=repla
l=len(str
t=0
for i=1 to l
c=Abs(As
if c>255 then
t=t+2
else
t=t+1
end if
if t>=strlen then
gotTopi
exit for
else
gotTopi
end if
next
gotTopic=
end function
'函数名:JoinC
'作 用:向地址中加入 ? 或 &
'参 数:strUrl ----网址
'返回值:加了 ? 或 & 的网址
'*********
function JoinChar(s
if strUrl="" then
JoinChar
exit function
end if
if InStr(strU
if InStr(strU
if InStr(strU
JoinCh
else
JoinCh
end if
else
JoinCha
end if
else
JoinChar
end if
end function
'函数名:Creat
'作 用:由给定的字符串生
'参 数:Constr--
'返回值:生成的关键
'*********
Function CreateKeyW
If Constr="" or IsNull(Con
CreateKeyW
Exit Function
End If
If Num="" or IsNumeric(
Num=2
End If
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Constr=Rep
Dim i,ConstrTe
For i=1 To Len(Constr
ConstrTemp
Next
If Len(Constr
ConstrTemp
Else
ConstrTemp
End If
CreateKeyW
End Function
'函数名:Check
'作 用:检查Url
'参 数:strUrl ------ 要检查Url
'=========
Function CheckUrl(s
Dim Re
Set Re=new RegExp
Re.IgnoreC
Re.Global=
Re.Pattern
If Re.test(st
CheckUrl=s
Else
CheckUrl="
End If
Set Rs=Nothing
End Function
'函数名:Scrip
'作 用:过滤html标记
'参 数:ConStr ------ 要过滤的字符串
'=========
Function ScriptHtml
Dim Re
Set Re=new RegExp
Re.IgnoreC
Re.Global=
Select Case FType
Case 1
Re.Pattern
ConStr=Re.
Case 2
Re.Pattern
ConStr=Re.
Case 3
Re.Pattern
ConStr=Re.
Re.Pattern
ConStr=Re.
End Select
ScriptHtml
Set Re=Nothing
End Function
'函数名:Remov
'作 用:完全去除html
'参 数:strHTML ------ 要过滤的字符串
'=========
Function RemoveHTML
Dim objRegExp,
Set objRegExp = New Regexp
objRegExp.
'取闭合的<>
objRegExp.
'进行匹配
Set Matches = objRegExp.
For Each Match in Matches
strHtml=Re
Next
RemoveHTML
Set objRegExp = Nothing
End Function
'函数名:Check
'作 用:检查文件夹是否存
'参 数:FolderPa
'=========
Function CheckDir(b
dim fso
Set fso = Server.Cre
If fso.Folder
'存在
CheckDir
Else
'不存在
CheckDir
End if
Set fso = nothing
End Function
'函数名:MakeN
'作 用:创建文件夹
'参 数:folderna
'=========
Function MakeNewsDi
dim fso
Set fso = Server.Cre
fso.Create
If fso.Folder
Else
End If
Set fso = nothing
End Function
'函数名:DelDi
'作 用:创建文件夹
'参 数:folderna
'=========
Function DelDir(byv
dim fso
Set fso = Server.Cre
If fso.Folder
fso.Delete
End If
Set fso = nothing
End Function
'函数名:IsObj
'作 用:检查组件是否已经
'参 数:strClass
'返回值:True
' False ----没有安装
'*********
Function IsObjInsta
IsObjInst
Err = 0
Dim xTestObj
Set xTestObj = Server.Cre
If 0 = Err Then IsObjInsta
Set xTestObj = Nothing
Err = 0
End Function
'函数名:strLe
'作 用:求字符串长度。汉
'参 数:str ----要求长度的字
'返回值:字符串长度
'*********
function strLength(
ON ERROR RESUME NEXT
dim WINNT_CHIN
WINNT_CHI
if WINNT_CHIN
dim l,t,c
dim i
l=len(str)
t=l
for i=1 to l
c=asc(mid
next
strLength=
else
strLength=
end if
if err.number
end function
'函数名:Creat
'作 用:创建多级目录,可
'参 数:要创建的目录名称
'返回逻辑值:Tru
'创建目录的根目录从
'*********
Function CreateMult
Dim objFSO,PhC
Dim i,ii,Creat
BlInfo = False
CreateFol
On Error Resume Next
Set objFSO = Server.Cre
If Err Then
Err.Clea
Exit Function
End If
CreateFol
If Left(Creat
'CreateF
End If
If Right(Crea
CreateFo
End If
CreateFol
For i = 0 to UBound(Cre
CreateFo
For ii = 0 to i
CreateF
Next
PhCreate
objFSO.
End If
Next
If Err Then
Err.Clea
Else
BlInfo = True
End If
Set objFSO=not
CreateMul
End Function
'函数名:FSOFi
'作 用:使用FSO读取文
'参 数:filename
'返回值:文件内容
'*********
function FSOFileRea
Dim objFSO,obj
Set objFSO = Server.Cre
Set objCountFi
FSOFileRea
objCountFi
Set objCountFi
Set objFSO = Nothing
End Function
'函数名:FSOli
'作 用:使用FSO读取文
'参 数:filename
' lineNum ----行数
'返回值:文件该行内
'*********
function FSOlinedit
if linenum < 1 then exit function
dim fso,f,temp
set fso = server.Cre
if not fso.fileEx
set f = fso.opente
if not f.AtEndofS
tempcnt = f.readall
f.close
set f = nothing
temparray = split(temp
if lineNum>ub
exit function
else
FSOlinedit
end if
end if
end function
'函数名:FSOli
'作 用:使用FSO写文件
'参 数:filename
' lineNum
' Lineconten
'返回值:无
'*********
function FSOlinewri
if linenum < 1 then exit function
dim fso,f,temp
set fso = server.Cre
if not fso.fileEx
set f = fso.opente
if not f.AtEndofS
tempcnt = f.readall
f.close
temparray = split(temp
if lineNum>ub
exit function
else
temparray(
end if
tempcnt = join(tempa
set f = fso.create
f.write tempcnt
end if
f.close
set f = nothing
end function
'函数名:Htmlm
'作 用:使用FSO创建文
'参 数:HtmlFold
' HtmlFilena
' HtmlConten
'*********
function Htmlmake(H
On Error Resume Next
dim filepath,f
filepath = HtmlFolder
Set fso = Server.Cre
&
Set fout = fso.Create
fout.write
fout.close
set fso=nothin
Set fso = Server.Cre
If fso.fileex
Response.W
Else
'Response.
Response.W
End If
Set fso = nothing
End function
'函数名:Htmld
'作 用:使用FSO删除文
'参 数:HtmlFold
' HtmlFilena
'*********
Sub Htmldel(Ht
dim filepath,f
filepath = HtmlFolder
Set fso = CreateObje
fso.Delete
Set fso = nothing
Set fso = Server.Cre
If fso.fileex
Response.W
Else
'Response.
Response.W
End If
Set fso = nothing
End Sub
'过程名:HTMLE
'作 用:过滤HTML格式
'参 数:fString ----转换内容
'=========
function HTMLEncode
If IsNull(fSt
fString = Replace(fS
fString = Replace(fS
fString = Replace(fS
fString = Replace(fS
fString = Replace(fS
fString = Replace(fS
fString = Replace(fS
fString = Replace(fS
fString = Replace(fS
fString = Replace(fS
HTMLEncode
else
HTMLEncode
end if
end function
'过程名:unHTM
'作 用:还原HTML格式
'参 数:fString ----转换内容
'=========
function unHTMLEnco
If IsNull(fSt
fString = Replace(fS
fString = Replace(fS
fString = Replace(fS
fString = Replace(fS
fString = Replace(fS
fString = Replace(fS
fString = Replace(fS
fString = Replace(fS
fString = Replace(fS
", Chr(10))
unHTMLEnco
else
unHTMLEnco
end if
end function
unhtmllist
if content <> "" then
unhtmllist
unhtmllist
unHtmllist
end if
end function
unhtmllist
if content <> "" then
unhtmllist
unhtmllist
unhtmllist
unHtmllist
")
end if
end function
htmllists=
if content <> "" then
htmllists=
htmllists=
htmllists=
end if
end function
uhtmllists
if content <> "" then
uhtmllists
uhtmllists
uhtmllists
uHtmllists
end if
end function
'过程: Sleep
'功能: 程序在此晢停几秒
'参数: iSeconds
'=========
Sub Sleep(iSec
response.W
Dim t:t=Timer(
While(Time
'Do Nothing
Wend
response.W
"
End Sub
'函数名:MyArr
'作 用:提取标签,以分
'参 数:ConStr ------提取地址
'=========
Function MyArray(By
Set objRegExp = New Regexp
objRegExp.
objRegExp.
objRegExp.
Set Matches =objRegExp
For Each Match in Matches
TempStr=Te
Next
Set Matches=no
TempStr=Ri
objRegExp.
TempStr=ob
objRegExp.
TempStr=ob
Set objRegExp=
Set Matches=no
TempStr=Re
MyArray="在
Else
MyArray=Te
End if
End Function
'函数名:randm
'作 用:产生6位随机数
'=========
Function randm
randomize
randm=Int(
End Function
%>