欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

获取远程flash并保存到本地

程序员文章站 2022-06-19 23:53:36
复制代码 代码如下:<% '--------------------------------------------------------------  ...
复制代码 代码如下:

<%
'--------------------------------------------------------------
 dbname = "../data/flash.mdb"          '更改数据库文件位置,强烈建议更改为.asp的文件!
 set conn = server.createobject("adodb.connection")
 connstr = "provider = microsoft.jet.oledb.4.0;data source = " & server.mappath(dbname)
 conn.open connstr
'------------------------------------------------------------
 set list = conn.execute("select * from system")
 webname = list("webname")
 weburl = list("weburl")
 webemail = list("webemail")
 zzname = list("zzname")
 qq = list("webqq")
%>

<%
server.scripttimeout=999999999
%>
<%
if request("overid")="" then
response.write "结束id不可为空"
response.end
elseif request("download")="" then
response.write "请选择是否下载"
response.end
end if
if request("id")=request("overid") then
response.write "采集任务结束"
response.end
end if
gourl1=request("id")
gourl1=gourl1+1
%>
<%
function getpy(str)
  for i=1 to len(str)
     getpy=getpy&getpychar(mid(str,i,1))
  next
end function
function geturl(url) 
   set retrieval = createobject("microsoft.xmlhttp") 
  with retrieval 
    .open "get", url, false
    .send 
    geturl = bytes2bstr(.responsebody)
    if len(.responsebody)<100 then
       response.write "获取远程文件 <a href="&url&" target=_blank>"&url&"</a> 失败。"
       response.write"<meta http-equiv=""refresh"" content=""0;url=getid.asp?id="&gourl1&""">"
       response.end
    end if
  end with 
  set retrieval = nothing 
end function
function bytes2bstr(vin) 
  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
function getkey(html,start,last)
  filearray=split(html,start)
  filearray2=split(filearray(1),last)
  getkey=filearray2(0)
end function
'------------------------------------
function saveremotefile(s_localfilename, s_remotefileurl)
    dim ads, retrieval, getremotedata
    dim berror
    berror = false
    saveremotefile = false
    on error resume next
    set retrieval = server.createobject("msxml2.serverxmlhttp")
    with retrieval
        .open "get", s_remotefileurl, false
        .send
        if .status = 200 then
            getremotedata = .responsebody
        else
            berror = true
        end if
    end with
    set retrieval = nothing
    if not berror then
        set ads = server.createobject("adodb.stream")
        with ads
            .type = 1
            .open
            .write getremotedata
            .savetofile server.mappath(s_localfilename), 2
            .cancel()
            .close()
        end with
        set ads=nothing
    end if
    if err.number = 0 and not berror then
        saveremotefile = true
    else
        err.clear
    end if
end function
%>
<%
flashid=request("id")
url="http://www.gameyes.com/swf/"&flashid&".htm" 
html = geturl(url) 
num=len(html)
if num<600 then
   response.write "<font color=red>flash序号:</font>  "&gourl1
   response.write "此页不存在,跳转下一个........<meta http-equiv=""refresh"" content=""0;url=getid.asp?id="&gourl1&"&overid="&request("overid")&"&download="&request("download")&""">"
   response.end
end if
nclassid1=getkey(html,"flash游戏 >> <a class=a href=../list/a_",".htm>")  '
nclass=getkey(html,"<a class=a href=../list/a_"&nclassid1&".htm>","</a>")
nclass=nclass&"类"
classid1=getkey(html,"class=a href='../list/",".htm'>")
classname=getkey(html,"class=a href='../list/"&classid1&".htm'>","</a>")
body=getkey(html,"<div id=""view_intro"">","</div>")
body=replace(body,"<tr>","")
body=replace(body,"<td>","")
pic1=getkey(html,"#secrt{background:url(../smallpic",") 2 2 no-repeat;border:1px")
pic1=replace(pic1,"_b.gif",".gif")
pic1=replace(pic1,"_b.jpg",".jpg")
pic="http://www.gameyes.com/smallpic"&pic1
pictype=right(pic,4)
flashurl=getkey(html,"download.asp?id="&flashid&"&swf=","""><img src=")
flashurl=replace(flashurl,"http://old.gameyes.com/flash","http://60.191.9.222/flash")
flashurl="http://old.gameyes.com/flash"&flashurl
flashname=getkey(html,"<title>","小游戏 休闲小游戏网 gameyes.com</title>")
%>
<%
  response.write "<font color=red>flash序号:</font>  "&gourl1
  response.write "<br>"
  response.write "<font color=red>flash名称:</font>  "&flashname
  response.write "<br>"
  response.write "<font color=red>所属大类:</font>  "&nclass
  response.write "<br>"
  response.write "<font color=red>所属二类:</font>  "&classname
  response.write "<br>"
  response.write "<font color=red>游戏介绍:</font>  "&body
  response.write "<br>"
  response.write "<font color=red>游戏小图:</font>  "&pic
  response.write "<br>"
  response.write "<font color=red>flash地址:</font>  "&flashurl
  response.write "<br>"
%>
<%
 if request("download")="yes" then
    response.write"开始下载flash<br>"
    response.flush
    result = saveremotefile("../flashfile/"&request("id")&".swf",""&flashurl&"")
    if result then
       response.write "<b>flash下载成功——保存在<a href=../flashfile/"&request("id")&".swf target=_blank>flashfile/"&request("id")&".swf</a><br>"
    else
       response.write "<b>flash保存失败</b><br>"
    end if
 end if
 if request("download")="yes" then
    response.write"开始下载flash图片<br>"
    response.flush
    result = saveremotefile("../flashpic/"&request("id")&pictype&"",""&pic&"")
   if result then
       response.write "<b>flash图片下载成功——保存在<a href=../flashpic/"&request("id")&pictype&" target=_blank>flashpic/"&request("id")&pictype&"</a>"
    else
       response.write "<b>flash图片保存失败</b><br>"
       response.write "此flash采集完毕,继续采集下一个<br><hr>"
    end if
 end if
%>
<%
dbpath = server.mappath("../data/flash.mdb")
set conn=server.createobject("adodb.connection")
    conn.open "driver={microsoft access driver (*.mdb)};dbq=" & dbpath
set rs=server.createobject("adodb.recordset")
    sql="select * from class where name='"&nclass&"'"
    rs.open sql,conn,1,3
    if rs.eof and rs.bof then
       rs.addnew
    end if
    rs("name")=nclass
    rs("classid")="0"
    rs.update
    rs.close
set rs = nothing
set rsc = conn.execute("select * from class where name='"&nclass&"'")
 nclassid=rsc("id")
 rsc.close
 set rsc=nothing
'处理flash的二级类别,如数据库中没有该类别,则增加
set rst=server.createobject("adodb.recordset")
sql="select * from class where name='"&classname&"'"
rst.open sql,conn,1,3
if rst.eof and rst.bof then
rst.addnew
end if
  rst("name")=classname
  rst("classid")=nclassid
  rst.update
rst.close
set rst = nothing
 '取类别的id号
 set rsc = conn.execute("select * from class where name='"&classname&"'")
 classid=rsc("id")
 rsc.close
 set rsc=nothing
'===================================================
'可以开始写入flash
set rs=server.createobject("adodb.recordset")
sql="select * from flash where flashname='"&flashname&"' and flashurl='"&flashurl&"'"
rs.open sql,conn,1,3
if rs.eof and rs.bof then
rs.addnew
end if
  rs("flashname")=flashname
if request("download")="yes" then
  rs("flashurl")="../flashfile/"&request("id")&".swf"
else
  rs("flashurl")=flashurl
end if
  rs("nclass")=nclassid
  rs("classid")=classid
  rs("classname")=classname
if request("download")="yes" then
  rs("pic")="../flashpic/"&request("id")&pictype
else
  rs("pic")=pic
end if
  rs("size")="500kb"
  rs("sj")=now()
  rs("body")=body
  rs("tj")="no"
  rs("hot")="1"
  rs("user")="admin"
  rs("zz")="未知"
  rs("geshou")="不祥"
  rs.update
rs.close
set rs = nothing
conn.close
set conn=nothing
%>
<%
dim gourl
gourl=flashid+1
response.write"<meta http-equiv=""refresh"" content=""0;url=getid.asp?id="&gourl&"&overid="&request("overid")&"&download="&request("download")&""">"
%>