根据网页源代码提取图片地址的asp代码index.asp这个页面是提交含有图片数据的网页源代码<%option explicitdim urlquan,tileft,tiright,resstop,ressbottom,guolvjs,kongbaiguolvjs=request.cookies("selalakaixin")("guolvjs")urlquan=request.cookies("selalakaixin")("urlquan")tileft=request.cookies("selalakaixin")("tileft")tiright=request.cookies("selalakaixin")("tiright")resstop=request.cookies("selalakaixin")("resstop")ressbottom=request.cookies("selalakaixin")("ressbottom")%><html><head><title>提交页面。提取src=后面内容,网页地址拼接,网页标题,网页图片地址提取测试</title></head><body><center><h2>1.<a href="index.asp">过滤提交</a>2.<a href="kaixin.asp">纯净提交</a>3.<a href="kaiaction.asp">服务器保存提交信息</a></h2><form method="post" action="kaixin.asp"><br>网页地址:<br><textarea name="urlquan" cols="120" rows="2"><%response.write urlquan%></textarea><br>标题前面部分内容:<br><textarea name="tileft" cols="120" rows="2"><%response.write tileft%></textarea><br>标题后面部分内容:<br><textarea name="tiright" cols="120" rows="2"><%response.write tiright%></textarea><br>图片地址块前面部分内容:<br><textarea name="resstop" cols="120" rows="3"><%response.write resstop%></textarea><br>图片地址块后面部分内容:<br><textarea name="ressbottom" cols="120" rows="3"><%response.write ressbottom%></textarea><br>网页所有内容:<br><textarea name="htmcontent" cols="120" rows="4" onMouseUp='this.select()' onFocus='this.select()'><%response.write kongbai%></textarea><br>过滤src后非图片文字:<br><textarea name="guolvjs" cols="120" rows="2"><%response.write guolvjs%></textarea><br><br><input type="submit" value="保存您的网站信息"><br><br><br><br><br><input type="reset" value="重新设置所用项目"></form><br>说明:<br>“标题前面部分内容”、“标题后面部分内容”两者中间包围的内容当作图片标题。“图片地址块前面部分内容”、“图片地址块后面部分内容”包围的内容,选择其中的图片地址,并且经过连接合并。前面的所有内容都位于“网页所有内容”中。</center></body></html>kaixin.asp接收过滤分析图片地址<%option explicitdim requ,urlquan,tileft,tiright,resstop,ressbottom,htmcontent,guolvjs,tlezong,tuzongguolvjs=trim(request.form("guolvjs"))urlquan=trim(request.form("urlquan"))tileft=trim(request.form("tileft"))tiright=trim(request.form("tiright"))resstop=trim(request.form("resstop"))ressbottom=trim(request.form("ressbottom"))htmcontent=trim(request.form("htmcontent"))for requ=1 to 15urlquan=replace(replace(urlquan,"//","/"),"http:/","http://",1,-1,1)nextresponse.cookies("selalakaixin")("guolvjs")=guolvjsresponse.cookies("selalakaixin")("urlquan")=urlquanresponse.cookies("selalakaixin")("tileft")=tileftresponse.cookies("selalakaixin")("tiright")=tirightresponse.cookies("selalakaixin")("resstop")=resstopresponse.cookies("selalakaixin")("ressbottom")=ressbottomresponse.cookies("selalakaixin").expires=date+365%><html><head><title>整理页面。提取src=后面内容,网页地址拼接,网页标题,网页图片地址提取测试</title><%'下面的函数计算在一个字符串中某个字符出现几次function fennum(waiurl,waifen)dim mqqif instr(waiurl,waifen) thenfor mqq=1 to len(waiurl)if mid(waiurl,mqq,len(waifen))=waifen thenfennum=fennum+1mqq=mqq+len(waifen)-1end ifnextelsefennum=0end ifend function'从头截取一段一个字符串中第n次出现的某个字符的位置function urlpin(newurl,newfen,newnum)dim fenong,fencountfor fenong=1 to len(newurl)if mid(newurl,fenong,len(newfen))=newfen thenfencount=fencount+1if fencount=newnum thenurlpin=mid(newurl,1,(fenong+len(newfen)-1))end iffenong=fenong+len(newfen)-1end ifnextend function'下面是拼接图片地址的函数,绝对地址不变,相对地址根据url地址拼接转换function imgurl(urlto,urlfen,htmas,linkfen)dim nlink,nurl,temurl,requfor requ=1 to 15htmas=replace(replace(htmas,"//","/"),"http:/","http://",1,-1,1)nextif instr(1,htmas,"?",1) thentemurl=left(htmas,instr(1,htmas,"?",1))elsetemurl=htmasend ifif instr(1,urlto,"?",1) thenurlto=left(urlto,instr(1,urlto,"?",1))end ifif fennum(urlto,urlfen)<3 thenurlto=urlto&"/"end ifnlink=fennum(temurl,linkfen)nurl=fennum(urlto,urlfen)'nlink为网页内链接含有的../数目,nurl为网址中含有的/数目if instr(1,left(htmas,7),"http://",1)=1 thenimgurl=htmaselseif instr(1,htmas,"/",1)=1 thenimgurl=urlpin(urlto,urlfen,3)&mid(htmas,2)elseif instr(1,left(htmas,3),linkfen,1)=0 thenimgurl=urlpin(urlto,urlfen,nurl)&htmaselseif instr(1,left(htmas,3),linkfen,1)=1 thenif nurl-nlink<=2 thenimgurl=urlpin(urlto,urlfen,3)&mid(htmas,nlink*len(linkfen)+1)elseimgurl=urlpin(urlto,urlfen,nurl-nlink)&mid(htmas,nlink*len(linkfen)+1)end ifend ifend function'下面是提取中间内容的函数:function tiress(trea,treb,trec)if instr(1,trea,trec,1) thentiress=left(trea,instr(1,trea,trec,1)-1)if instr(1,tiress,treb,1) thentiress=right(tiress,(len(tiress)-instr(1,tiress,treb,1)-len(treb)+1))elsetiress="色辣辣http://www.selala.com/图片整合系统"end ifelsetiress="色辣辣http://www.selala.com/图片整合系统"end ifend function'下面的函数是过滤图片地址中非常规字符function imgsift(imgqu)imgsift=replace(replace(replace(replace(replace(replace(imgqu,"'",""),chr(34),""),chr(10),""),chr(13),""),chr(9),""),chr(32),"")end function'下面的函数是提取图片块(一段字符中含有多个图片地址)中的图片地址function imgchoose(chimg,qutype)dim imgseed,n,i,jif len(guolvjs)>0 thenchimg=replace(chimg,guolvjs,"")end ifimgseed=split(chimg,qutype,-1,1)for n=lbound(imgseed)+1 to ubound(imgseed)i=instr(1,imgseed(n),">",1)j=instr(1,imgseed(n),chr(32),1)if (isnumeric(i)=true and isnumeric(i)=true and (i-j)<0 and i>0 and j>0) thenimgchoose=imgchoose&imgurl(urlquan,"/",imgsift(left(imgseed(n),i-1)),"../")elseif (isnumeric(i)=true and isnumeric(i)=true and (i-j)>0 and i>0 and j>0) thenimgchoose=imgchoose&imgurl(urlquan,"/",imgsift(left(imgseed(n),j-1)),"../")elseif (isnumeric(i)=true and isnumeric(i)=true and j=0 and i>0) thenimgchoose=imgchoose&imgurl(urlquan,"/",imgsift(left(imgseed(n),i-1)),"../")elseif (isnumeric(i)=true and isnumeric(i)=true and i=0 and j>0) thenimgchoose=imgchoose&imgurl(urlquan,"/",imgsift(left(imgseed(n),j-1)),"../")elseif (isnumeric(i)=true and isnumeric(i)=true and i=0 and j=0) thenimgchoose=imgchoose&imgurl(urlquan,"/",imgsift(imgseed(n)),"../")end ifnextend functiontlezong=server.htmlencode(replace(tiress(htmcontent,tileft,tiright)," ",","))'标题编码tuzong=imgchoose(tiress(htmcontent,resstop,ressbottom)," src=")%></head><body><center><h2>1.<a href="index.asp">过滤提交</a>2.<a href="kaixin.asp">纯净提交</a>3.<a href="kaiaction.asp">服务器保存提交信息</a></h2><form method="post" action="kaiaction.asp"><br><input type="hidden" name="kaiyan1" value="wangyou"><br><input type="hidden" name="kaiyan2" value="wangyan"><br>图片名称:<br><input type="text" name="total" maxlength="255" value="<%response.write tlezong%>" size="80"><br>图片地址序列:<br><textarea name="picdz" cols="80" rows="10"><%response.write tuzong%></textarea><br><input type="submit" value="提交表中所有数据到网站"><br><br><br><br><input type="reset" value="清除表中所有数据"></form><br><%dim spj,spmspm=split(tuzong,"http://",-1,1)for spj=lbound(spm) to ubound(spm)if spj<1 thenresponse.write tlezongresponse.write "<br>"else%><a href=http://<%response.write trim(spm(spj))%> target=_blank><img src=http://<%response.write trim(spm(spj))%> width=500 border=0></a><br><%end ifnext%></center></body></html> kaiaction.asp接收图片地址和标题,保存到数据库<%option explicitdim conn,total,picdz,sql,rs,kaiyan1,kaiyan2set conn=server.createobject("adodb.connection")conn.open "driver={microsoft access driver (*.mdb)};dbq="+server.mappath("wwwselalacom.mdb")'图片标题地址数据接受处理系统kaiyan1=request.form("kaiyan1")kaiyan2=request.form("kaiyan2")if (kaiyan1="wangyou" and kaiyan2="wangyan") thenkaiyan1=kaiyan2elseresponse.write "<script language='javascript'>"&vbcrlfresponse.write "alert('对不起,密码不正确')"&vbcrlfresponse.write "history.go(-1);"&vbcrlfresponse.write "</script>"&vbcrlfconn.closeset conn=nothingresponse.endend if'------------------读取数据--------------total=replace(replace(replace(replace(replace(replace(replace(replace(replace(left(request.form("total"),255),chr(32),""),chr(10),""),"'",""),"?",""),"<",""),"*",""),"[",""),"]",""),chr(13),"")picdz=replace(replace(replace(replace(replace(replace(left(request.form("picdz"),60000),chr(32),""),chr(10),""),"'",""),"<",""),"*",""),chr(13),"")if total="" then total="色辣辣图片整合系统"'------------------判断图片地址序列--------if trim(picdz)="" or instr(1,picdz,"http://",1)=0 thenresponse.write "<script language='javascript'>"&vbcrlfresponse.write "alert('图片地址序列须要输入或者图片地址有误')"&vbcrlfresponse.write "history.go(-1);"&vbcrlfresponse.write "</script>"&vbcrlfconn.closeset conn=nothingresponse.endend if''------------------数据编码,防止可执行小脚本--------total=server.htmlencode(total)picdz=server.htmlencode(picdz)'------------------把信息写进数据库-----------sql="insert into selala(total,picdz,selalatime) values('"&total&"','"&picdz&"','"&now()&"')" conn.execute(sql)conn.closeset conn=nothingresponse.write "<script language='javascript'>"&vbcrlfresponse.write "history.go(-2);"&vbcrlfresponse.write "</script>"&vbcrlf%>
本文转自分瓜博客51CTO博客,原文链接http://blog.51cto.com/aiqing/3329如需转载请自行联系原作者
aiqing