仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2740|回复: 20
打印 上一主题 下一主题

[学习教程] ASP教程之使用ASP法式完成将近程页面的一切内容下...

[复制链接]
小妖女 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-3 23:30:16 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
asp,jsp,php是web开发的三大技术,asp简单易用且有microsoft做靠山,jsp功能强大是因为有java支持,php则开源跨平台.在国内,asp应用范围最广,jsp发展势头最猛,php则处于劣势.这可能与公司的支持以及技术的培训有关.法式|下载|页面     之前发过一个器材,是将近程的内容,按阅读器输出后,将它转为二进制流下载到当地,但局限性对照多,这个代码可以将近程页面的一切内容,包含近程办事器的CSS,JS,JPG,Gif,第一层上面的页面,swf,等等...
  代码的利用:
  将上面的代码保留为downfile.asp放到你的站点一个目次下,然后在谁人目次外面创立一个叫downfile的文件夹,一切失掉的内容都将保留在downfile文件夹里。
  在阅读器中输出
  http://你的地址/downfile.asp?url=http://www.百度.com/index.html
  那末就将百度首页的一切文件都下载到当地的谁人叫downfile的文件夹中..
  这个代码比你的手工OE可要恬逸多了,并且会将获得的文件,依照本来近程的途径,创立文件夹,分种别保留文件..
<%
'####################
'代码的主体函数局部均源自于收集
'####################
'设置超时的工夫
Server.ScriptTimeout=9999
'##############
'文件保留函数
'#############
function SaveToFile(from,tofile)
on error resume next
dim geturl,objStream,imgs
geturl=trim(from)
Mybyval=getHTTPstr(geturl)
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type =1
objStream.Open
objstream.write Mybyval
objstream.SaveToFile tofile,2
objstream.Close()
set objstream=nothing
if err.number<>0 then err.Clear
end function  

'##############
'字符处置交换
'#############
function geturlencodel(byval url)'中文文件名转换
Dim i,code
geturlencodel=""
if trim(Url)="" then exit function
for i=1 to len(Url)
code=Asc(mid(Url,i,1))
if code<0 Then code = code + 65536
If code>255 Then
geturlencodel=geturlencodel&"%"&Left(Hex(Code),2)&"%"&Right(Hex(Code),2)
else
geturlencodel=geturlencodel&mid(Url,i,1)
end if
next
end function
'##############
'XML获得近程页面入手下手
'#############
function getHTTPPage(url)
on error resume next
dim http
set http=Server.createobject("Msxml2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then exit function
getHTTPPage=bytes2BSTR(Http.responseBody)
set http=nothing
if err.number<>0 then err.Clear
end function  

Function bytes2BSTR(vIn)
dim strReturn
dim i,ThisCharCode,NextCharCode
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
'##############
'XML获得近程页面停止,这段是小偷法式都通用的局部
'#############

'##############
'分化地址,获得文件名
'#############
function getFileName(byval filename)
if instr(filename,"/")>0 then
fileExt_a=split(filename,"/")
getFileName=lcase(fileExt_a(ubound(fileExt_a)))
if instr(getFileName,"?")>0 then
getFileName=left(getFileName,instr(getFileName,"?")-1)
end if
else
getFileName=filename
end if
end function  

'##############
'获得近程页面函数
'#############
function getHTTPstr(url)
on error resume next
dim http
set http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then exit function
getHTTPstr=Http.responseBody
set http=nothing
if err.number<>0 then err.Clear
end function  

'##############
'FSO处置函数,创立目次
'#############
Function CreateDIR(ByVal LocalPath) '创立目次的法式,假如有多级目次,则一级一级的创立
On Error Resume Next
LocalPath = WordStr(LocalPath, "\", "/")
Set FileObject = server.CreateObject("Scripting.FileSystemObject")
patharr = Split(LocalPath, "/")
path_level = UBound(patharr)
For I = 0 To path_level
If I = 0 Then pathtmp = patharr(0) & "/" Else pathtmp = pathtmp & patharr(I) & "/"
cpath = Left(pathtmp, Len(pathtmp) - 1)
If Not FileObject.FolderExists(cpath) Then FileObject.CreateFolder cpath  

Next
Set FileObject = Nothing
If Err.Number <> 0 Then
CreateDIR = False
Err.Clear
Else
CreateDIR = True
End If
End Function

function GetfileExt(byval filename)
fileExt_a=split(filename,".")
GetfileExt=lcase(fileExt_a(ubound(fileExt_a)))
end function

'##############
'若何获得虚拟的途径
'#############
function getvirtual(str,path,urlhead)
if left(str,7)="http://" then
url=str
elseif left(str,1)="/" then
start=instrRev(str,"/")
if start=1 then
url="/"
else
url=left(str,start)
end if
url=urlhead&url
elseif left(str,3)="../" then
str1=mid(str,inStrRev(str,"../")+2)
ar=split(str,"../")
lv=ubound(ar)+1
ar=split(path,"/")
url="/"
for i=1 to (ubound(ar)-lv)
url=url&ar(i)
next
url=url&str1
url=urlhead&url
else
url=urlhead&str
end if
getvirtual=url
end function

'上面是示范性的代码
dim dlpath
'创立一个文件夹,以便寄存这些获得的数据
virtual="/downfile/"
truepath=server.MapPath(virtual)

if request("url")<> "" then
url=request("url")
fn=getFileName(url)
urlhead=left(url,(instr(replace(url,"//",""),"/")+1))
urlpath=replace(left(url,instrRev(url,"/")),urlhead,"")
strContent = getHTTPPage(url)
mystr=strContent
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "(src|href)=.[^\>]+? "
Set Matches =objRegExp.Execute(strContent)
For Each Match in Matches
str=Match.Value
str=replace(str,"src=","")
str=replace(str,"href=","")
str=replace(str,"""","")
str=replace(str,"'","")
filename=GetfileName(str)
getRet=getVirtual(str,urlpath,urlhead)
temp=WordStr(getRet,"//","**")
start=instr(temp,"/")
endt=instrRev(temp,"/")-start+1
if start>0 then
repl=virtual&mid(temp,start)&" "
'response.Write repl&"<br>"
mystr=WordStr(mystr,str,repl)

dir=mid(temp,start,endt)
temp=truepath&WordStr(dir,"/","\")
CreateDir(temp)
response.Write getRet&"||"&temp&filename&"<br>"
response.Write "胜利获得"&filename&"这个文件<br>"
response.Write "并将"&filename&"保留在"&temp&"<br><br>"
response.Write "<HR>"
SaveToFile getRet,temp&filename
end if
Next
set Matches=nothing
else
response.write "请输出一个地址!"
end if
%>
ASP在国内异常流行,因为国内大多使用的是盗版的Windows和盗版的SQLServer,而ASP+COM+SQLServer实际上也是一种不错的搭配,其性能也不输于PHP+MYSQL,特别是Windows系统和SQLServer都有图形界面,比APACHE和MYSQL易于维护,因此对于不重视知识产权的国家来说也是一种不错的选择。
小妖女 该用户已被删除
沙发
 楼主| 发表于 2015-3-22 22:57:44 | 显示全部楼层
跟学别的语言一样,先掌握变量,流程控制语句(就是ifwhileselect)等,函数/过程,数组
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-6-12 00:16

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表