根据网页源代码提取图片地址的asp代码

简介:
根据网页源代码提取图片地址的asp代码

index.asp这个页面是提交含有图片数据的网页源代码

<%
option explicit
dim urlquan,tileft,tiright,resstop,ressbottom,guolvjs,kongbai
guolvjs=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 explicit
dim requ,urlquan,tileft,tiright,resstop,ressbottom,htmcontent,guolvjs,tlezong,tuzong
guolvjs=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 15
urlquan=replace(replace(urlquan,"//","/"),"http:/"," http://" ,1,-1,1)
next
response.cookies("selalakaixin")("guolvjs")=guolvjs
response.cookies("selalakaixin")("urlquan")=urlquan
response.cookies("selalakaixin")("tileft")=tileft
response.cookies("selalakaixin")("tiright")=tiright
response.cookies("selalakaixin")("resstop")=resstop
response.cookies("selalakaixin")("ressbottom")=ressbottom
response.cookies("selalakaixin").expires=date+365
%>
<html>
<head>
<title>整理页面。提取src=后面内容,网页地址拼接,网页标题,网页图片地址提取测试</title>
<%
'下面的函数计算在一个字符串中某个字符出现几次
function fennum(waiurl,waifen)
dim mqq
if instr(waiurl,waifen) then
for mqq=1 to len(waiurl)
if mid(waiurl,mqq,len(waifen))=waifen then
fennum=fennum+1
mqq=mqq+len(waifen)-1
end if
next
else
fennum=0
end if
end function
'从头截取一段一个字符串中第n次出现的某个字符的位置
function urlpin(newurl,newfen,newnum)
dim fenong,fencount
for fenong=1 to len(newurl)
if mid(newurl,fenong,len(newfen))=newfen then
fencount=fencount+1
if fencount=newnum then
urlpin=mid(newurl,1,(fenong+len(newfen)-1))
end if
fenong=fenong+len(newfen)-1
end if
next

end function

'下面是拼接图片地址的函数,绝对地址不变,相对地址根据url地址拼接转换
function imgurl(urlto,urlfen,htmas,linkfen)
dim nlink,nurl,temurl,requ
for requ=1 to 15
htmas=replace(replace(htmas,"//","/"),"http:/"," http://" ,1,-1,1)
next
if instr(1,htmas,"?",1) then
temurl=left(htmas,instr(1,htmas,"?",1))
else
temurl=htmas
end if
if instr(1,urlto,"?",1) then
urlto=left(urlto,instr(1,urlto,"?",1))
end if

if fennum(urlto,urlfen)<3 then
urlto=urlto&"/"
end if

nlink=fennum(temurl,linkfen)
nurl=fennum(urlto,urlfen)
'nlink为网页内链接含有的../数目,nurl为网址中含有的/数目
if instr(1,left(htmas,7)," http://" ,1)=1 then
imgurl=htmas
elseif instr(1,htmas,"/",1)=1 then
imgurl=urlpin(urlto,urlfen,3)&mid(htmas,2)
elseif instr(1,left(htmas,3),linkfen,1)=0 then
imgurl=urlpin(urlto,urlfen,nurl)&htmas
elseif instr(1,left(htmas,3),linkfen,1)=1 then
if nurl-nlink<=2 then
imgurl=urlpin(urlto,urlfen,3)&mid(htmas,nlink*len(linkfen)+1)
else
imgurl=urlpin(urlto,urlfen,nurl-nlink)&mid(htmas,nlink*len(linkfen)+1)
end if

end if
end function


'下面是提取中间内容的函数:
function tiress(trea,treb,trec)
if instr(1,trea,trec,1) then
tiress=left(trea,instr(1,trea,trec,1)-1)
if instr(1,tiress,treb,1) then
tiress=right(tiress,(len(tiress)-instr(1,tiress,treb,1)-len(treb)+1))
else
tiress="色辣辣 http://www.selala.com/ 图片整合系统"
end if
else
tiress="色辣辣 http://www.selala.com/ 图片整合系统"
end if
end 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,j
if len(guolvjs)>0 then
chimg=replace(chimg,guolvjs,"")
end if
imgseed=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) then
imgchoose=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) then
imgchoose=imgchoose&imgurl(urlquan,"/",imgsift(left(imgseed(n),j-1)),"../")

elseif (isnumeric(i)=true and isnumeric(i)=true and j=0 and i>0) then
imgchoose=imgchoose&imgurl(urlquan,"/",imgsift(left(imgseed(n),i-1)),"../")

elseif (isnumeric(i)=true and isnumeric(i)=true and i=0 and j>0) then
imgchoose=imgchoose&imgurl(urlquan,"/",imgsift(left(imgseed(n),j-1)),"../")

elseif (isnumeric(i)=true and isnumeric(i)=true and i=0 and j=0) then
imgchoose=imgchoose&imgurl(urlquan,"/",imgsift(imgseed(n)),"../")

end if
next
end function

tlezong=server.htmlencode(replace(tiress(htmcontent,tileft,tiright),"&nbsp;",","))
'标题编码
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,spm
spm=split(tuzong," http://" ,-1,1)
for spj=lbound(spm) to ubound(spm)
if spj<1 then
response.write tlezong
response.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 if
next
%>
</center>
</body>
</html> 


kaiaction.asp接收图片地址和标题,保存到数据库


<%
option explicit
dim conn,total,picdz,sql,rs,kaiyan1,kaiyan2
set 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") then
kaiyan1=kaiyan2
else
response.write "<script language='javascript'>"&vbcrlf
response.write "alert('对不起,密码不正确')"&vbcrlf
response.write "history.go(-1);"&vbcrlf
response.write "</script>"&vbcrlf
conn.close
set conn=nothing
response.end
end 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 then
response.write "<script language='javascript'>"&vbcrlf
response.write "alert('图片地址序列须要输入或者图片地址有误')"&vbcrlf
response.write "history.go(-1);"&vbcrlf
response.write "</script>"&vbcrlf
conn.close
set conn=nothing
response.end
end if
'
'------------------数据编码,防止可执行小脚本--------
total=server.htmlencode(total)
picdz=server.htmlencode(picdz)
'------------------把信息写进数据库-----------
sql="insert into selala(total,picdz,selalatime) values('"&total&"','"&picdz&"','"&now()&"')" 
conn.execute(sql)
conn.close
set conn=nothing
response.write "<script language='javascript'>"&vbcrlf
response.write "history.go(-2);"&vbcrlf
response.write "</script>"&vbcrlf

%>

本文转自分瓜博客51CTO博客,原文链接http://blog.51cto.com/aiqing/3329如需转载请自行联系原作者


aiqing

相关文章
|
11月前
|
开发框架 .NET Apache
301重定向代码合集(iis,asp,php,asp.net,apache)
301重定向代码合集(iis,asp,php,asp.net,apache)
274 0
|
前端开发 .NET 开发框架