看到上面这些文字描述也许好多人要头晕了,那看一下具体的实现过程吧(因为我对ASP比较熟悉,所以我用ASP来实现它了,用其它的平台也是可以实现的)。首先让我先引入我自己写的一个类,用来分析和转移图片的,详细的说明请看我的另一篇文章:用asp自动解析网页中的图片地址,并将其保存到本地服务器(http://www.csdn.net/develop/read_article.htm?id=15585)
class blacksmith
'The Class "blacksmith" is Created by Linzhang Chen
'It could use for copy images form other server which contain in the web
dim size,baseurl,basefilename,tofolder,servername,processstr,firstoldimg,firstnewimg
public Function saveimage(from, tofile)
Dim geturl, objStream, imgs,s
If size = "" Then
size = 0
End If
geturl = Trim(from)
imgs = getHTTPPage(geturl)
s = size * 512
If Len(imgs) > s Then
Set objStream = CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objStream.Write imgs
objStream.SaveToFile tofile, 2
objStream.Close
Set objStream = Nothing
saveimage = True
Else
saveimage = False
End If
End Function
private Function getHTTPPage(url)
On Error Resume Next
Dim http
Set http = CreateObject("MSXML2.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
|