利用MSXML2.XmlHttp和Adodb.Stream采集圖片
更新時(shí)間:2008年05月11日 21:36:28 作者:
asp下經(jīng)常用來采集的兩個(gè)組件結(jié)合使用例子
利用MSXML2.XmlHttp和Adodb.Stream
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ASP采集圖片測試</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<%
Function Gethttpimg(Url)
On Error Resume Next
Dim Http
Set Http=Server.Createobject("MSXML2.XmlHttp")
Http.Open "Get",Url,False
Http.Send()
If Http.Readystate<>4 Then Exit Function
Gethttpimg=Http.Responsebody
Set Http=Nothing
If Err.Number<>0 Then Err.Clear
End Function
Sub Save2Local(From,Tofile)
Dim Geturl,Objstream,Imgs
Geturl=Trim(From)
Imgs=Gethttpimg(Geturl)
Set Objstream = Server.Createobject("Adodb.Stream")
Objstream.Type =1
Objstream.Open
Objstream.Write Imgs
Objstream.Savetofile Tofile,2
Objstream.Close()
Set Objstream=Nothing
'Response.Write("The Img has saved!")
End Sub
Call Save2Local("http://www.dbjr.com.cn/logos.gif",Server.MapPath("google.gif"))
%>
</body>
</html>
復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ASP采集圖片測試</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<%
Function Gethttpimg(Url)
On Error Resume Next
Dim Http
Set Http=Server.Createobject("MSXML2.XmlHttp")
Http.Open "Get",Url,False
Http.Send()
If Http.Readystate<>4 Then Exit Function
Gethttpimg=Http.Responsebody
Set Http=Nothing
If Err.Number<>0 Then Err.Clear
End Function
Sub Save2Local(From,Tofile)
Dim Geturl,Objstream,Imgs
Geturl=Trim(From)
Imgs=Gethttpimg(Geturl)
Set Objstream = Server.Createobject("Adodb.Stream")
Objstream.Type =1
Objstream.Open
Objstream.Write Imgs
Objstream.Savetofile Tofile,2
Objstream.Close()
Set Objstream=Nothing
'Response.Write("The Img has saved!")
End Sub
Call Save2Local("http://www.dbjr.com.cn/logos.gif",Server.MapPath("google.gif"))
%>
</body>
</html>
相關(guān)文章
用XML+FSO+JS實(shí)現(xiàn)服務(wù)器端文件的選擇效果
用XML+FSO+JS實(shí)現(xiàn)服務(wù)器端文件的選擇效果實(shí)現(xiàn)代碼,需要的朋友可以參考下2006-06-06利用xmlhttp和adodb.stream加緩存技術(shù)下載遠(yuǎn)程Web文件
利用xmlhttp和adodb.stream加緩存技術(shù)下載遠(yuǎn)程Web文件...2006-06-06實(shí)例講解ASP實(shí)現(xiàn)抓取網(wǎng)上房產(chǎn)信息
實(shí)例講解ASP實(shí)現(xiàn)抓取網(wǎng)上房產(chǎn)信息...2006-09-09ASP小偷(遠(yuǎn)程數(shù)據(jù)獲取)程序的入門教程
ASP小偷(遠(yuǎn)程數(shù)據(jù)獲取)程序的入門教程...2006-06-06