一小偷类!!有兴趣的可以看看
程序员文章站
2023-10-20 12:38:45
类代码 (cls.asp) <% class clsthief private strurl &nbs...
类代码 (cls.asp)
<%
class clsthief
private strurl ' 偷取地址
private strvalue ' 偷取的内容,所有内容
private strresult ' 偷取结果,可以具体某一块内容
private flag ' 是否已经偷过
'-------初始化类--------'
private sub class_initialize()
strurl=""
strvalue=""
strresult=""
flag=false
end sub
'------类结束-----------'
private sub class_terminate()
end sub
'------初始化url属性----'
public property let url(byval iurl)
strurl = iurl
end property
'------返回输出内容----'
public property get value
value=strvalue
end property
public property get result
result=strresult
end property
'------------文字处理-----------'
private function bytestobstr(body,cset)
dim objstream
set objstream = server.createobject("adodb.stream")
objstream.type = 1
objstream.mode =3
objstream.open
objstream.write body
objstream.position = 0
objstream.type = 2
objstream.charset = cset
bytestobstr = objstream.readtext
objstream.close
set objstream = nothing
end function
'-------文字处理-------'
private function ichange(str)
dim finalstr
dim icharcode
dim inextcode
for i = 1 to lenb(str)
icharcode = ascb(midb(str,i,1))
if icharcode < &h80 then
finalstr = finalstr & chr(icharcode)
else
inextcode = ascb(midb(str,i+1,1))
finalstr = finalstr & chr(clng(icharcode) * &h100 + cint(inextcode))
i = i + 1
end if
next
ichange = finalstr
end function
'-------内容抓取--------'
public sub seize()
if strurl<>"" then
dim iconnect
set iconnect = createobject("microsoft.xmlhttp")
iconnect.open "get",strurl,false
iconnect.send()
strvalue = bytestobstr(iconnect.responsebody,"gb2312")
flag=true
set iconnect = nothing
if err.number<>0 then err.clear
else
response.write("请设置url的属性,即url地址")
end if
end sub
'------内容分析------'
public sub assay(head,headcusor,bot,botcusor)
if flag = false then call seize()
if instr(strvalue,head) and instr(strvalue,bot) then
dim inum
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 = "没有匹配到相关记录,请检查开始标记代码是否唯一"
end if
end sub
'----替换空格及回车行----'
public sub shift()
if flag= false then call seize()
strresult=replace(replace(strresult , vbcr,""),vblf,"")
end sub
'------对内容自定义替换----'
public sub change(oldstr,newstr)
if flag=false then call seize()
strresult = replace(strresult,oldstr,newstr)
end sub
'--------自定义正则进行匹配---'
public sub pickbyreg(patrn)
if isget_= false then call seize()
dim tempreg,match,matches,content
set tempreg=new regexp
tempreg.ignorecase=true
tempreg.global=true
tempreg.pattern=patrn
set matches=tempreg.execute(value_)
for each match in matches
content=content&match.value&"<!--lkstar-->"
next
strvalue=content
set matches=nothing
set tempreg=nothing
end sub
'--------如果有首页文件则转入-----------'
public sub checkfile(foldername,filename)
dim url
set fs=server.createobject("scripting.filesystemobject")
if fs.folderexists(server.mappath("./")&"\"&foldername&"\"&filename) then
set fs = nothing
url = foldername&"/"&filename
response.write url
'response.redirect url
end if
end sub
'------生成文件------'
public sub makefile(foldername,filename)
set fs=server.createobject("scripting.filesystemobject")
if foldername<>"" then
if not fs.folderexists(server.mappath("/"&foldername&"/")) then
response.write "文件不存在"
fs.createfolder(foldername)
else
response.write "文件存在"
end if
end if
set crfi=fs.createtextfile(server.mappath("./")&"\"&foldername&"\"&filename)
crfi.writeline(strresult)
set crfi=nothing
set fs=nothing
dim url
url = foldername&"/"&filename
response.redirect url
end sub
'-------查看偷出的代码----'
public sub look()
dim tempstr
tempstr="<script>function runex(){var winex2 = 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(); }function savefile(){var win=window.open('','','top=10000,left=10000');win.document.write(document.all.asdf.innertext);win.document.execcommand('saveas','','javascript.htm');win.close();}</script><center><textarea id=asdf name=textfield rows=32 wrap=virtual cols=""120"">"&strresult&"</textarea><br><br><input name=button onclick=runex() type=button value=""查看效果""> <input name=button onclick=asdf.select() type=button value=""全选""> <input name=button onclick=""asdf.value=''"" type=button value=""清空""> <input onclick=savefile(); type=button value=""保存代码""></center>"
response.write(tempstr)
end sub
end class
%>
引用页(test.asp)
<!--#include file="cls.asp"-->
<%
dim mythief,value
set mythief = new clsthief '实例化类
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" '生成文件
set mythief = nothing
'response.write value
%>
<%
class clsthief
private strurl ' 偷取地址
private strvalue ' 偷取的内容,所有内容
private strresult ' 偷取结果,可以具体某一块内容
private flag ' 是否已经偷过
'-------初始化类--------'
private sub class_initialize()
strurl=""
strvalue=""
strresult=""
flag=false
end sub
'------类结束-----------'
private sub class_terminate()
end sub
'------初始化url属性----'
public property let url(byval iurl)
strurl = iurl
end property
'------返回输出内容----'
public property get value
value=strvalue
end property
public property get result
result=strresult
end property
'------------文字处理-----------'
private function bytestobstr(body,cset)
dim objstream
set objstream = server.createobject("adodb.stream")
objstream.type = 1
objstream.mode =3
objstream.open
objstream.write body
objstream.position = 0
objstream.type = 2
objstream.charset = cset
bytestobstr = objstream.readtext
objstream.close
set objstream = nothing
end function
'-------文字处理-------'
private function ichange(str)
dim finalstr
dim icharcode
dim inextcode
for i = 1 to lenb(str)
icharcode = ascb(midb(str,i,1))
if icharcode < &h80 then
finalstr = finalstr & chr(icharcode)
else
inextcode = ascb(midb(str,i+1,1))
finalstr = finalstr & chr(clng(icharcode) * &h100 + cint(inextcode))
i = i + 1
end if
next
ichange = finalstr
end function
'-------内容抓取--------'
public sub seize()
if strurl<>"" then
dim iconnect
set iconnect = createobject("microsoft.xmlhttp")
iconnect.open "get",strurl,false
iconnect.send()
strvalue = bytestobstr(iconnect.responsebody,"gb2312")
flag=true
set iconnect = nothing
if err.number<>0 then err.clear
else
response.write("请设置url的属性,即url地址")
end if
end sub
'------内容分析------'
public sub assay(head,headcusor,bot,botcusor)
if flag = false then call seize()
if instr(strvalue,head) and instr(strvalue,bot) then
dim inum
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 = "没有匹配到相关记录,请检查开始标记代码是否唯一"
end if
end sub
'----替换空格及回车行----'
public sub shift()
if flag= false then call seize()
strresult=replace(replace(strresult , vbcr,""),vblf,"")
end sub
'------对内容自定义替换----'
public sub change(oldstr,newstr)
if flag=false then call seize()
strresult = replace(strresult,oldstr,newstr)
end sub
'--------自定义正则进行匹配---'
public sub pickbyreg(patrn)
if isget_= false then call seize()
dim tempreg,match,matches,content
set tempreg=new regexp
tempreg.ignorecase=true
tempreg.global=true
tempreg.pattern=patrn
set matches=tempreg.execute(value_)
for each match in matches
content=content&match.value&"<!--lkstar-->"
next
strvalue=content
set matches=nothing
set tempreg=nothing
end sub
'--------如果有首页文件则转入-----------'
public sub checkfile(foldername,filename)
dim url
set fs=server.createobject("scripting.filesystemobject")
if fs.folderexists(server.mappath("./")&"\"&foldername&"\"&filename) then
set fs = nothing
url = foldername&"/"&filename
response.write url
'response.redirect url
end if
end sub
'------生成文件------'
public sub makefile(foldername,filename)
set fs=server.createobject("scripting.filesystemobject")
if foldername<>"" then
if not fs.folderexists(server.mappath("/"&foldername&"/")) then
response.write "文件不存在"
fs.createfolder(foldername)
else
response.write "文件存在"
end if
end if
set crfi=fs.createtextfile(server.mappath("./")&"\"&foldername&"\"&filename)
crfi.writeline(strresult)
set crfi=nothing
set fs=nothing
dim url
url = foldername&"/"&filename
response.redirect url
end sub
'-------查看偷出的代码----'
public sub look()
dim tempstr
tempstr="<script>function runex(){var winex2 = 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(); }function savefile(){var win=window.open('','','top=10000,left=10000');win.document.write(document.all.asdf.innertext);win.document.execcommand('saveas','','javascript.htm');win.close();}</script><center><textarea id=asdf name=textfield rows=32 wrap=virtual cols=""120"">"&strresult&"</textarea><br><br><input name=button onclick=runex() type=button value=""查看效果""> <input name=button onclick=asdf.select() type=button value=""全选""> <input name=button onclick=""asdf.value=''"" type=button value=""清空""> <input onclick=savefile(); type=button value=""保存代码""></center>"
response.write(tempstr)
end sub
end class
%>
引用页(test.asp)
<!--#include file="cls.asp"-->
<%
dim mythief,value
set mythief = new clsthief '实例化类
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" '生成文件
set mythief = nothing
'response.write value
%>