asp图片采集代码

称来判断图片是否存在,

判断远程图片是否存在,原理是利用XMLHTTP.status来判断
function CheckURL(byval A_strUrl)
set XMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")
XMLHTTP.open "HEAD",A_strUrl,false
XMLHTTP.send()
CheckURL=(XMLHTTP.status=200)
set XMLHTTP = nothing
end function
Dim imgurl
imgurl="UploadFiles/2007829144940734.gif"
if CheckURL(imgurl) then
response.write "图片存在"
else
response.write "图片不存在"
end if

判断远程图片是否存在[js代码]

{
var oReq = new ActiveXObject("Microsoft.XMLHTTP")
oReq.open("Get","UploadFiles/2007829144941621.gif",false);
oReq.send();
//alert(oReq.status)
if(oReq.status==404)
alert('不存在');
else
alert("存在")
}

下面是看保存代码.

在做采集程序的时候,需要将被采集网页上的图片保存下来,这样,首先要得到被采集网页上的图片地址,然后将图片保存下来
  
函数如下:
以下是引用片段:
Function ShowPic(str)  
  Set objRegExp = New Regexp'设置配置对象   
  objRegExp.IgnoreCase = True'忽略大小写   
  objRegExp.Global = True'设置为全文搜索   
  objRegExp.Pattern = "<img.+?>"  
  '为了确保能准确地取出图片地址所以分为两层配置:首先找到里面的<img>标签,
然后再取出里面的图片地址后面的getimgs函数就是实现后一个功能的。   
strs=trim(str)   
Set Matches =objRegExp.Execute(strs)'开始执行配置   
For Each Match in Matches   
RetStr = RetStr &getimgs( Match.Value )'执行第二轮的匹配   
Next   
ShowPic = RetStr  
End Function  
Function getimgs(str)   
getimgs=""   
Set objRegExp1 = New Regexp   
objRegExp1.IgnoreCase = True   
objRegExp1.Global = True   
objRegExp1.Pattern = "http://.+?"""'取出里面的地址   
set mm=objRegExp1.Execute(str)   
For Each Match1 in mm   
getimgs=getimgs&left(Match1.Value,len(Match1.Value)-1)&"||"
 '把里面的地址串起来备用   
next   
End Function   
'取得图片内容  
function getHTTPPage(url)   
on error resume next   
dim http   
set http=server.createobject("MSXML2.XMLHTTP")
 '使用xmlhttp的方法来获得图片的内容   
Http.open "GET",url,false   
Http.send()   
if Http.readystate<>4 then   
exit function   
end if   
getHTTPPage=Http.responseBody   
set http=nothing   
if err.number<>0 then err.Clear   
end function   
'保存图片  
function saveimage(from,tofile)   
dim geturl,objStream,imgs   
geturl=trim(from)   
imgs=gethttppage(geturl)'取得图片的具休内容的过程   
Set objStream = Server.CreateObject("ADODB.Stream")
'建立ADODB.Stream对象,必须要ADO 2.5以上版本   
objStream.Type =1'以二进制模式打开   
objStream.Open   
objstream.write imgs'将字符串内容写入缓冲   
objstream.SaveToFile server.mappath(tofile),2'-将缓冲的内容写入文件   
objstream.Close()'关闭对象   
set objstream=nothing   
end function   
'调用实例  
Dim strpic,i,fname  
strpic = ShowPic("<DIV align=center><IMG src=""图片地址"" border=0></DIV>")  
strpic = Split(strpic,"||")  
If UBound(strpic) > 0 Then   
For i = 0 To UBound(strpic) - 1  
'保存图片  
fname=cstr(i&mid(strpic(i),instrrev(strpic(i),".")))   
saveimage(strpic(i),fname)  
Next  
Else  
End If  

时间: 2024-07-30 23:32:54

asp图片采集代码的相关文章

asp 文件采集代码

asp 文件采集代码 我们用到xmlhttp来抓取远程服务器文件的内容再把它转换成相关编码 <% Function getHTTPPage(Path)         t = GetBody(Path)         getHTTPPage=BytesToBstr(t,"UTF-8") End function Function GetBody(url)         on error resume next         Set Retrieval = CreateObj

asp 防采集代码

Dim AppealNum,AppealCount AppealNum=10 '同一IP60秒内请求限制10次 AppealCount=Request.Cookies("AppealCount") If AppealCount="" Then response.Cookies("AppealCount")=1 AppealCount=1 response.cookies("AppealCount").expires=datea

asp 防采集代码 二

user_agent=Request.ServerVariables("HTTP_USER_AGENT") http_reffer=Request.ServerVariables("HTTP_REFERER") server_name=Request.ServerVariables("SERVER_NAME") '检查当前用户是否是蜘蛛人 function check(user_agent) allow_agent=split("Bai

图片分页代码

图片分页代码,asp图片分页代码,asp图片分页源代码及教程 <table width="700" border="1" cellspacing="0" cellpadding="0"> <% sql="select * from [table] order by time1 desc" rs.open sql,conn,1,1 if rs.eof then else   rs.pages

ASP替换、保存远程图片实现代码_应用技巧

ASP通过函数来实现替换.保存远程图片,完成自动采集图片.提取图片的功能,函数中自动判断重复图片,智能分析链接路径,并转成成相对的图片地址保存在你指定的网站目录中,我们可将此函数用在后台的编辑器中,当你复制了含有图片的内容后,本代码会自动帮你上传图片.同时本代码也是采集程序中的重要处理函数,函数代码如下: Function ReplaceSaveRemoteFile(ConStr,strInstallDir,strChannelDir,SaveTf,TistUrl) If ConStr="$Fa

asp.net保存远程图片的代码_实用技巧

注意:并没有实现CSS中的图片采集,且图片的正则还有待完善. 复制代码 代码如下: using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using

ASP替换、保存远程图片实现代码

ASP通过函数来实现替换.保存远程图片,完成自动采集图片.提取图片的功能,函数中自动判断重复图片,智能分析链接路径,并转成成相对的图片地址保存在你指定的网站目录中,我们可将此函数用在后台的编辑器中,当你复制了含有图片的内容后,本代码会自动帮你上传图片.同时本代码也是采集程序中的重要处理函数,函数代码如下: Function ReplaceSaveRemoteFile(ConStr,strInstallDir,strChannelDir,SaveTf,TistUrl) If ConStr="$Fa

asp采集代码示例

下面是一侧ASP采集页面内容最基础的必备源代码,修改以下的代码需要有一定的ASP基础. 以下是引用片段:< %  '功能:asp采集代码  '作者:wangsdong  '备注:支持原创程序,请保留此信息,谢谢  url="http://sports.sina.com.cn/k/2008-09-15/04593948756.shtml"  str=getHTTPPage(url)  title=strcut(str,"<h1 id=""arti

一段ASP防采集的代码

采集 一段ASP防采集的代码<%        '作用:文字防复制乱码 函数        'Date:2006-3-6        '作者:blue2004        '参数str 为原文,str1作者也是你自己,reslut产生乱码的种子        Function ReadToCode(str,Str1,result)                dim name                dim i,j,k                If isnull(str) th