关于一个图片小偷的程序,不知道高手们能不能解决!!!!!正则表达式高手快进!!!

jiangjinsong 2007-11-28 08:44:53
<%
'函数功能:远程图片自动保存到本地服务器,并利用aspjpeg为图片加上水印
'(注意:请先在目录下创建images目录,用来保存临时图片)
'本程序需要在服务器上安装"aspjpeg组件"否则无法正常使用
'也可以只取'''''22222222'''''''以上的部分,这部分可以保存图片,第二部分是进行水印增加
'使用方法,请保存为saveimg.asp
'saveimg.asp?url=http://siyizhu.com/logo.gif 即可以取下图片啦,HOHO. 其他需要加的功能,大家自己扩展好啦
'如何获取其他后缀名的文件呢? 当然也可以啦
'(jpg|gif|png|bmp)改成(mp3)明白吧? 就是取mp3后缀的文件名.以此类推. 嘻嘻

Server.ScriptTimeOut=99999
savepath=images
url=request.QueryString("url")

''function myreplace(str)
'newstr=str
'set objregEx = new RegExp
'objregEx.IgnoreCase = true
'objregEx.Global = true
'objregEx.Pattern = "http://(.+?)\.(jpg|gif|png|bmp)" '定义文件后缀
'set matches = objregEx.execute(str)
'for each match in matches
'newstr=replace(newstr,match.value,saveimg(match.value))
'next
'myreplace=newstr
'end function

function saveimg(url1)

'temp=split(url,".")
'以下是用时间与随机数重命名文件名
'文件名重命名结束
set xmlhttp=server.createobject("Microsoft.XMLHTTP")
xmlhttp.open "get",url1,false
xmlhttp.send
html=xmlhttp.ResponseBody
set xmlhttp=nothing
set objregEx = new RegExp
objregEx.IgnoreCase = true
objregEx.Global = true
objregEx.Pattern = "http://(.+?)\.(jpg|gif|png|bmp)" '定义文件后缀
set matches = objregEx.execute(html)
imgstrs=""
for each match in matches
imgstrs=match.value&"|"&imgstrs
next
strp=split(imgstrs,"|")
for i=LBound(strp) to UBound(strp)
set xmlhttp=server.createobject("Microsoft.XMLHTTP")
xmlhttp.open "get",strp(i),false
xmlhttp.send
img=xmlhttp.ResponseBody
set xmlhttp=nothing
set objAdostream=server.createobject("ADODB.Stream")
objAdostream.Open()
objAdostream.type=1
objAdostream.Write(img)
randomize
ranNum=int(90000*rnd)+10000
filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&".jpg"
objAdostream.SaveToFile(server.mappath(savepath&filename))
objAdostream.SetEOS
response.Write("ok")
set objAdostream=nothing
next
'''''''222222222'''''''''''
'saveimg=savepath&filename '获取保存路径
'Dim Jpeg
'Set Jpeg = Server.CreateObject("Persits.Jpeg")
'Jpeg.Open Server.MapPath(saveimg) '打开保存图片的路径

' 添加文字水印
'Jpeg.Canvas.Font.Color = &HFF0000' 红色
'Jpeg.Canvas.Font.Family = "宋体"
'Jpeg.Canvas.Font.Bold = True
'Jpeg.Canvas.Print Jpeg.OriginalWidth-200,Jpeg.OriginalHeight-50, "siyizhu.com" '水印离左边的距离,离顶端的距离,这个是放在右下脚了
'保存文件
'Jpeg.Save Server.MapPath(saveimg) '保存添加水印后的图片

' 注销对象
'Set Jpeg = Nothing
end function
saveimg(url)
%>
我想应该是在正则表达式上出了一些问题,它应该能能匹配想这样的/images/图片地址才行吧,而且还要替换,我今天看了正则表达式的内容,简直晕头转向,想高手指点一下!!!!!!!!!!!!!!!!!!!!!!!!
...全文
361 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
ling9918 2007-11-29
  • 打赏
  • 举报
回复
最后改这样了..

<%
'函数功能:远程图片自动保存到本地服务器,并利用aspjpeg为图片加上水印
'(注意:请先在目录下创建images目录,用来保存临时图片)
'本程序需要在服务器上安装"aspjpeg组件"否则无法正常使用
'也可以只取'''''22222222'''''''以上的部分,这部分可以保存图片,第二部分是进行水印增加
'使用方法,请保存为saveimg.asp
'saveimg.asp?url=http://siyizhu.com/logo.gif 即可以取下图片啦,HOHO. 其他需要加的功能,大家自己扩展好啦
'如何获取其他后缀名的文件呢? 当然也可以啦
'(jpg|gif|png|bmp)改成(mp3)明白吧? 就是取mp3后缀的文件名.以此类推. 嘻嘻

Server.ScriptTimeOut=99999
savepath=images
url="http://www.cmfu.com/index.asp"
host="http://www.cmfu.com"
''function myreplace(str)
'newstr=str
'set objregEx = new RegExp
'objregEx.IgnoreCase = true
'objregEx.Global = true
'objregEx.Pattern = "http://(.+?)\.(jpg|gif|png|bmp)" '定义文件后缀
'set matches = objregEx.execute(str)
'for each match in matches
'newstr=replace(newstr,match.value,saveimg(match.value))
'next
'myreplace=newstr
'end function

function saveimg(url1)

'temp=split(url,".")
'以下是用时间与随机数重命名文件名
'文件名重命名结束
set xmlhttp=server.createobject("Microsoft.XMLHTTP")
xmlhttp.open "get",url1,false
xmlhttp.send
html=xmlhttp.ResponseBody
html=BytesToBstr(html)
set xmlhttp=nothing
set objregEx = new RegExp
set subReg = new RegExp
objregEx.IgnoreCase = true
objregEx.Global = true
objregEx.Pattern = "<img\s+[^>]*src\s*=\s*([""']?)((?:/|http://|ftp://|/s*)?)([^""'>]*)\1\s+[^>]*/?>"
set matches = objregEx.execute(html)
imgstrs=""
for each match in matches
temp=match.value
temp=Replace(temp,"<","<")
temp=Replace(temp,">",">")
' Response.write (temp)
' Response.write ("<br />")
src=match.SubMatches(2)
from=match.SubMatches(1)
if from="/" then
src=host&from&src
elseif from="http://" Or from="ftp://" then
src=from&src
else
src=host&"/"&src
end if
Response.write (src)
Response.write ("<br />")
next

'strp=split(imgstrs,"|")
'for i=LBound(strp) to UBound(strp)
'set xmlhttp=server.createobject("Microsoft.XMLHTTP")
'xmlhttp.open "get",strp(i),false
'xmlhttp.send
'img=xmlhttp.ResponseBody
'set xmlhttp=nothing
'set objAdostream=server.createobject("ADODB.Stream")
'objAdostream.Open()
'objAdostream.type=1
'objAdostream.Write(img)
'randomize
'ranNum=int(90000*rnd)+10000
'filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&".jpg"
'objAdostream.SaveToFile(server.mappath(savepath&filename))
'objAdostream.SetEOS
'response.Write("ok")
'set objAdostream=nothing
'next
'''''''222222222'''''''''''
'saveimg=savepath&filename '获取保存路径
'Dim Jpeg
'Set Jpeg = Server.CreateObject("Persits.Jpeg")
'Jpeg.Open Server.MapPath(saveimg) '打开保存图片的路径

' 添加文字水印
'Jpeg.Canvas.Font.Color = &HFF0000' 红色
'Jpeg.Canvas.Font.Family = "宋体"
'Jpeg.Canvas.Font.Bold = True
'Jpeg.Canvas.Print Jpeg.OriginalWidth-200,Jpeg.OriginalHeight-50, "siyizhu.com" '水印离左边的距离,离顶端的距离,这个是放在右下脚了
'保存文件
'Jpeg.Save Server.MapPath(saveimg) '保存添加水印后的图片

' 注销对象
'Set Jpeg = Nothing
end function
Function BytesToBstr(body)
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 = "GB2312"
'转换原来默认的UTF-8编码转换成GB2312编码,否则直接用XMLHTTP调用有中文字符的网页得到的将是乱码
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
saveimg(url)
%>

jiangjinsong 2007-11-29
  • 打赏
  • 举报
回复
老板来,要做其他事,迟点结贴,o(∩_∩)o...
ling9918 2007-11-29
  • 打赏
  • 举报
回复

for each match1 in matches
imgstrs=match1.value&"|"&imgstrs
response.Write match1.value
next

改成:
for each match1 in matches
imgstrs=match1 .SubMatches(0)&"<br>|"&imgstrs
response.Write match1.SubMatches(0)
next

ling9918 2007-11-29
  • 打赏
  • 举报
回复
去捕获组的值,不是匹配的值


for each match1 in matches
imgstrs=match1.value&"|"&imgstrs
response.Write match1.value
next

for each match1 in matches
imgstrs=match.SubMatches(0)&"<br>|"&imgstrs
response.Write match1.SubMatches(0)
next

jiangjinsong 2007-11-29
  • 打赏
  • 举报
回复
我想把匹配值显示出来看看,但是就是不行,出什么问题了?
<%
'函数功能:远程图片自动保存到本地服务器,并利用aspjpeg为图片加上水印
'(注意:请先在目录下创建images目录,用来保存临时图片)
'本程序需要在服务器上安装"aspjpeg组件"否则无法正常使用
'也可以只取'''''22222222'''''''以上的部分,这部分可以保存图片,第二部分是进行水印增加
'使用方法,请保存为saveimg.asp
'saveimg.asp?url=http://siyizhu.com/logo.gif 即可以取下图片啦,HOHO. 其他需要加的功能,大家自己扩展好啦
'如何获取其他后缀名的文件呢? 当然也可以啦
'(jpg|gif|png|bmp)改成(mp3)明白吧? 就是取mp3后缀的文件名.以此类推. 嘻嘻

Server.ScriptTimeOut=99999
savepath=images
url=request.QueryString("url")

''function myreplace(str)
'newstr=str
'set objregEx = new RegExp
'objregEx.IgnoreCase = true
'objregEx.Global = true
'objregEx.Pattern = "http://(.+?)\.(jpg|gif|png|bmp)" '定义文件后缀
'set matches = objregEx.execute(str)
'for each match in matches
'newstr=replace(newstr,match.value,saveimg(match.value))
'next
'myreplace=newstr
'end function

function saveimg(url1)

'temp=split(url,".")
'以下是用时间与随机数重命名文件名
'文件名重命名结束
set xmlhttp=server.createobject("Microsoft.XMLHTTP")
xmlhttp.open "get",url1,false
xmlhttp.send
html=xmlhttp.ResponseBody
set xmlhttp=nothing
set objregEx = new RegExp
objregEx.IgnoreCase = true
objregEx.Global = true
objregEx.Pattern = "<img\s+[^>]*src\s*=\s*(?:""([^""']*)""|'([^""'])'|([^""'>]*))\s+[^>]*/?>"
set matches = objregEx.execute(html)
imgstrs=""
for each match1 in matches
imgstrs=match1.value&"|"&imgstrs
response.Write match1.value
next
'strp=split(imgstrs,"|")
'for i=LBound(strp) to UBound(strp)
'set xmlhttp=server.createobject("Microsoft.XMLHTTP")
'xmlhttp.open "get",strp(i),false
'xmlhttp.send
'img=xmlhttp.ResponseBody
'set xmlhttp=nothing
'set objAdostream=server.createobject("ADODB.Stream")
'objAdostream.Open()
'objAdostream.type=1
'objAdostream.Write(img)
'randomize
'ranNum=int(90000*rnd)+10000
'filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&".jpg"
'objAdostream.SaveToFile(server.mappath(savepath&filename))
'objAdostream.SetEOS
'response.Write("ok")
'set objAdostream=nothing
'next
'''''''222222222'''''''''''
'saveimg=savepath&filename '获取保存路径
'Dim Jpeg
'Set Jpeg = Server.CreateObject("Persits.Jpeg")
'Jpeg.Open Server.MapPath(saveimg) '打开保存图片的路径

' 添加文字水印
'Jpeg.Canvas.Font.Color = &HFF0000' 红色
'Jpeg.Canvas.Font.Family = "宋体"
'Jpeg.Canvas.Font.Bold = True
'Jpeg.Canvas.Print Jpeg.OriginalWidth-200,Jpeg.OriginalHeight-50, "siyizhu.com" '水印离左边的距离,离顶端的距离,这个是放在右下脚了
'保存文件
'Jpeg.Save Server.MapPath(saveimg) '保存添加水印后的图片

' 注销对象
'Set Jpeg = Nothing
end function
saveimg(url)
%>
传递参数为::http://localhost/ok.asp?url=http://www.baidu.com
jiangjinsong 2007-11-29
  • 打赏
  • 举报
回复
让我测试看看
ling9918 2007-11-29
  • 打赏
  • 举报
回复
测试OK.

'正则改成这样:
objregEx.Pattern = "<img\s+[^>]*src\s*=\s*(?:""([^""']*)""|'([^""'])'|([^""'>]*))\s+[^>]*/?>"
'另外需要对返回进行编码转换
html=BytesToBstr(html)
Function BytesToBstr(body)
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 = "GB2312"
'转换原来默认的UTF-8编码转换成GB2312编码,否则直接用XMLHTTP调用有中文字符的网页得到的将是乱码
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
jiangjinsong 2007-11-29
  • 打赏
  • 举报
回复
但是这个也替换所有了如果图片网址是src="/upfile/123.jpg"那可以替换,但是编程src="eell/upfile/123.jpg"就不可以了吧,这样的最多只能是保存一个特定网页的图片而已吧,我最终想是实现像动易那一样子,只要是图片都能保存到服务器
个性小资 2007-11-29
  • 打赏
  • 举报
回复
正则的效率是高,不过你想怎么写的时间,已经replace完了
个性小资 2007-11-29
  • 打赏
  • 举报
回复
replace("/upfile/","http://123.com/upfile/")

replace("upfile/","http://123.com/upfile/")

这样就可以了
jiangjinsong 2007-11-29
  • 打赏
  • 举报
回复
单引号都改为?\'
ling9918 2007-11-29
  • 打赏
  • 举报
回复
你可以找个Emeditor的文本编辑器,支持正则的,然后随便找个网站用他打开源代码查找验证下正则式!
第一个捕获组就是图片地址了.
ling9918 2007-11-29
  • 打赏
  • 举报
回复
忘记你用vbscript了,单引号请转码先.
jiangjinsong 2007-11-29
  • 打赏
  • 举报
回复
能说的详细一点吗?
chinastorm 2007-11-29
  • 打赏
  • 举报
回复
开始用正则,然后用replace替换一下吧
jiangjinsong 2007-11-29
  • 打赏
  • 举报
回复
<%
'函数功能:远程图片自动保存到本地服务器,并利用aspjpeg为图片加上水印
'(注意:请先在目录下创建images目录,用来保存临时图片)
'本程序需要在服务器上安装"aspjpeg组件"否则无法正常使用
'也可以只取'''''22222222'''''''以上的部分,这部分可以保存图片,第二部分是进行水印增加
'使用方法,请保存为saveimg.asp
'saveimg.asp?url=http://siyizhu.com/logo.gif 即可以取下图片啦,HOHO. 其他需要加的功能,大家自己扩展好啦
'如何获取其他后缀名的文件呢? 当然也可以啦
'(jpg|gif|png|bmp)改成(mp3)明白吧? 就是取mp3后缀的文件名.以此类推. 嘻嘻

Server.ScriptTimeOut=99999
savepath=images
url=request.QueryString("url")

''function myreplace(str)
'newstr=str
'set objregEx = new RegExp
'objregEx.IgnoreCase = true
'objregEx.Global = true
'objregEx.Pattern = "http://(.+?)\.(jpg|gif|png|bmp)" '定义文件后缀
'set matches = objregEx.execute(str)
'for each match in matches
'newstr=replace(newstr,match.value,saveimg(match.value))
'next
'myreplace=newstr
'end function

function saveimg(url1)

'temp=split(url,".")
'以下是用时间与随机数重命名文件名
'文件名重命名结束
set xmlhttp=server.createobject("Microsoft.XMLHTTP")
xmlhttp.open "get",url1,false
xmlhttp.send
html=xmlhttp.ResponseBody
set xmlhttp=nothing
set objregEx = new RegExp
objregEx.IgnoreCase = true
objregEx.Global = true
objregEx.Pattern = "<img\s+[^>]*src\s*=\s*(?:"([^"']*)"|'([^"'])'|([^"'>]*))\s+[^>]*/?>"
set matches = objregEx.execute(html)
imgstrs=""
for each match in matches
imgstrs=match.value&"|"&imgstrs
response.Write imgstrs
next
'strp=split(imgstrs,"|")
'for i=LBound(strp) to UBound(strp)
'set xmlhttp=server.createobject("Microsoft.XMLHTTP")
'xmlhttp.open "get",strp(i),false
'xmlhttp.send
'img=xmlhttp.ResponseBody
'set xmlhttp=nothing
'set objAdostream=server.createobject("ADODB.Stream")
'objAdostream.Open()
'objAdostream.type=1
'objAdostream.Write(img)
'randomize
'ranNum=int(90000*rnd)+10000
'filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&".jpg"
'objAdostream.SaveToFile(server.mappath(savepath&filename))
'objAdostream.SetEOS
'response.Write("ok")
'set objAdostream=nothing
'next
'''''''222222222'''''''''''
'saveimg=savepath&filename '获取保存路径
'Dim Jpeg
'Set Jpeg = Server.CreateObject("Persits.Jpeg")
'Jpeg.Open Server.MapPath(saveimg) '打开保存图片的路径

' 添加文字水印
'Jpeg.Canvas.Font.Color = &HFF0000' 红色
'Jpeg.Canvas.Font.Family = "宋体"
'Jpeg.Canvas.Font.Bold = True
'Jpeg.Canvas.Print Jpeg.OriginalWidth-200,Jpeg.OriginalHeight-50, "siyizhu.com" '水印离左边的距离,离顶端的距离,这个是放在右下脚了
'保存文件
'Jpeg.Save Server.MapPath(saveimg) '保存添加水印后的图片

' 注销对象
'Set Jpeg = Nothing
end function
saveimg(url)
%>
好想不太对,有些部分被注释掉了
jiangjinsong 2007-11-29
  • 打赏
  • 举报
回复
牛!!结贴
ling9918 2007-11-29
  • 打赏
  • 举报
回复
在加上图片尺寸限制,类型限制,自动打开下级超链接搜索,搜索深度,哈哈,完善他.
ling9918 2007-11-29
  • 打赏
  • 举报
回复
这个也行:

<img\s+[^>]*src\s*=\s*([""']?)((?:/|http://|ftp://|/s*)?)([^""'\s>]*)\1\s+[^>]*/?>
>]
ling9918 2007-11-29
  • 打赏
  • 举报
回复

objregEx.Pattern = "<img\s+[^>]*src\s*=\s*([""']?)((?:/|http://|ftp://|/s*)?)([^""'>]*(?:jpe?g|gif|bmp|png))\1\s+[^>]*/?>"
加载更多回复(3)

28,392

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧