类代码(cls.asp)
<%
ClassclsThief
PrivatestrUrl'偷取地址
PrivatestrValue'偷取的内容,所有内容
PrivatestrResult'偷取结果,可以具体某一块内容
Privateflag'是否已经偷过
'-------初始化类--------'
PrivateSubClass_Initialize()
strUrl=""
strValue=""
strResult=""
flag=false
EndSub
'------类结束-----------'
PrivateSubClass_Terminate()
EndSub
'------初始化url属性----'
PublicPropertyLeturl(ByValiurl)
strUrl=iurl
EndProperty
'------返回输出内容----'
publicpropertygetvalue
value=strValue
endproperty
publicpropertygetresult
result=strResult
endproperty
'------------文字处理-----------'
privateFunctionBytesToBstr(body,Cset)
dimobjstream
setobjstream=Server.CreateObject("adodb.stream")
objstream.Type=1
objstream.Mode=3
objstream.Open
objstream.Writebody
objstream.Position=0
objstream.Type=2
objstream.Charset=Cset
BytesToBstr=objstream.ReadText
objstream.Close
setobjstream=nothing
EndFunction
'-------文字处理-------'
privateFunctionIchange(str)
DimfinalStr
DimicharCode
DiminextCode
Fori=1Tolenb(str)
icharCode=ascb(midb(str,i,1))
IficharCode<&H80Then
finalStr=finalStr&chr(icharCode)
Else
inextCode=ascb(midb(str,i+1,1))
finalstr=finalstr&chr(clng(icharCode)*&H100+cint(inextCode))
i=i+1
EndIf
Next
Ichange=finalStr
EndFunction
'-------内容抓取--------'
PublicsubSeize()
ifstrUrl<>""then
dimiconnect
Seticonnect=CreateObject("Microsoft.XMLHTTP")
iconnect.open"GET",strUrl,false
iconnect.send()
strValue=BytesToBSTR(iconnect.responseBody,"GB2312")
flag=true
seticonnect=nothing
iferr.number<>0thenerr.Clear
else
response.write("请设置url的属性,即url地址")
endif
endsub
'------内容分析------'
PublicsubAssay(head,headCusor,bot,botCusor)
ifflag=falsethencallSeize()
ifinstr(strValue,head)andinstr(strValue,bot)then
diminum
inum=len(strValue)-instr(strValue,head)-len(head)-headCusor
strValue=right(strValue,inum)
inum=instr(strValue,bot)-1+botCusor
strResult=left(strValue,inum)
else
strResult="没有匹配到相关记录,请检查开始标记代码是否唯一"
endif
endsub
'----替换空格及回车行----'
publicsubShift()
ifflag=falsethencallSeize()
strResult=replace(replace(strResult,vbCr,""),vbLf,"")
endsub
'------对内容自定义替换----'
PublicsubChange(oldStr,newStr)
ifflag=falsethencallSeize()
strResult=replace(strResult,oldStr,newStr)
endsub
'--------自定义正则进行匹配---'
publicsubpickByReg(patrn)
ifisGet_=falsethencallSeize()
dimtempReg,match,matches,content
settempReg=newRegExp
tempReg.IgnoreCase=true
tempReg.Global=true
tempReg.Pattern=patrn
setmatches=tempReg.execute(value_)
foreachmatchinmatches
content=content&match.value&"<>"
next
strValue=content
setmatches=nothing
settempReg=nothing
endsub
'--------如果有首页文件则转入-----------'
PublicsubCheckFile(folderName,fileName)
dimurl
Setfs=Server.CreateObject("Scripting.FileSystemObject")
iffs.FolderExists(server.MapPath("./")&""&folderName&""&fileName)then
setfs=nothing
url=folderName&"/"&fileName
response.writeurl
'response.redirecturl
endif
endsub
'------生成文件------'
PublicsubMakeFile(folderName,fileName)
Setfs=Server.CreateObject("Scripting.FileSystemObject")
iffolderName<>""then
ifnotfs.FolderExists(server.MapPath("/"&folderName&"/"))then
response.write"文件不存在"
fs.CreateFolder(folderName)
else
response.write"文件存在"
endif
endif
SetCrFi=fs.CreateTextFile(server.MapPath("./")&""&folderName&""&fileName)
Crfi.Writeline(strResult)
setCrFi=nothing
setfs=nothing
dimurl
url=folderName&"/"&fileName
response.redirecturl
endsub
'-------查看偷出的代码----'
publicsublook()
dimtempstr
tempstr="<SCRIPT>functionrunEx(){varwinEx2=window.open("""",""winEx2"",""width=500,height=300,status=yes,menubar=no,scrollbars=yes,resizable=yes"");winEx2.document.open(""text/html"",""replace"");winEx2.document.write(unescape(event.srcElement.parentElement.children[0].value));winEx2.document.close();}functionsaveFile(){varwin=window.open('','','top=10000,left=10000');win.document.write(document.all.asdf.innerText);win.document.execCommand('SaveAs','','javascript.htm');win.close();}</SCRIPT><center><TEXTAREAid=asdfname=textfieldrows=32wrap=VIRTUALcols=""120"">"&strResult&"</TEXTAREA><BR><BR><INPUTname=Buttononclick=runEx()type=buttonvalue=""查看效果""><INPUTname=Buttononclick=asdf.select()type=buttonvalue=""全选""><INPUTname=Buttononclick=""asdf.value=''""type=buttonvalue=""清空""><INPUTonclick=saveFile();type=buttonvalue=""保存代码""></center>"
response.Write(tempstr)
endsub
endclass
%>
引用页(test.asp)
<>
<%
dimmyThief,value
setmyThief=newclsThief'实例化类
myThief.CheckFile"","index.html"'检测是否已经偷过并生成
myThief.url="http://www.sohu.com"'目标URL
myThief.Seize'开始偷取
myThief.Assay"<html>","-7","</html>","7"'剪切标记
myThief.Change"择优","浪人"'进行替换
value=myThief.result'最后得到的内容
myThief.MakeFile"","index.html"'生成文件
setmyThief=nothing
'response.writevalue
%>