用ASP VBS xmlhttp adodbstream下载和保存图片的代码
网络编程 2021-07-05 10:58www.168986.cn编程入门
函数
function saveFile(data,recfilen)
set Astream=CreateObject("Adodb.Stream")'asp Server.CreateObject("Adodb.Stream")
fxt=mid(recfilen,InStrRev(recfilen,".")+1)
txt=false
if fxt="asp" or fxt="xml" or fxt="aspx" or fxt="php" or fxt="txt" or fxt="jsp" then
txt=true
end if
if txt then
Astream.type=2 '1 bin,2 txt
else
Astream.type=1 '1 bin,2 txt
end if
Astream.Mode = 3' adModeRead =1
' adModeReadWrite =3
' adModeRecursive =4194304
' adModeShareDenyNone =16
' adModeShareDenyRead =4
' adModeShareDenyWrite =8
' adModeShareExclusive =12
' adModeUnknown =0
' adModeWrite =2
Astream.open
'Astream.CharSet = "GB2312"
'Astream.LoadFromFile(recfilen) '装载文件
'Assp=Astream.size
Astream.Position =0 '装载文件时设置为Assp
'Astream.Writetext tmpstr00,1
if txt then
data=bytes2bstr(data)
Astream.Writetext data,1
else
Astream.Write data
end if
Astream.SaveToFile recfilen,2
Astream.close
end function
'Server.
function downimg(url)
set oXMLHTTP =CreateObject("Microsoft.XMLHTTP")'asp Server.CreateObject("Microsoft.XMLHTTP")
data_got=""
oXMLHTTP.open "GET",url, false
oXMLHTTP.setRequestHeader "Aept-Encoding"," gzip, deflate"
oXMLHTTP.setRequestHeader "User-Agent","Mozilla/4.0 (patible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 2.0.50727)"
oXMLHTTP.send
rtstatus=oXMLHTTP.status
data_got=oXMLHTTP.responsebody
filename=mid(url,InStrRev(url,"/")+1)
if rtstatus=200 then
data_got=oXMLHTTP.responsebody
saveFile data_got,filename
else
data_got=""
end if
set oXMLHTTP =nothing
end function
function bytes2bstr(vin) '二进制转化为汉字
strreturn = ""
for i = 1 to lenb(vin)
thischarcode = ascb(midb(vin,i,1))
if thischarcode < &h80 then
strreturn = strreturn & chr(thischarcode)
else
nextcharcode = ascb(midb(vin,i+1,1))
strreturn = strreturn & chr(clng(thischarcode) &h100 + cint(nextcharcode))
i = i + 1
end if
next
bytes2bstr = strreturn
end function
使用方法
imgurl="http://.163car./UpFile/CarImages/0092/S_b_20051241127326f6uew1s.jpg" '图片
downimg(imgurl)
imgurl="HTTP://login.zydn./news.asp" '文字页面
downimg(imgurl)
把代码保存为vbs文件,不需要iis就可以运行~
代码如下:
function saveFile(data,recfilen)
set Astream=CreateObject("Adodb.Stream")'asp Server.CreateObject("Adodb.Stream")
fxt=mid(recfilen,InStrRev(recfilen,".")+1)
txt=false
if fxt="asp" or fxt="xml" or fxt="aspx" or fxt="php" or fxt="txt" or fxt="jsp" then
txt=true
end if
if txt then
Astream.type=2 '1 bin,2 txt
else
Astream.type=1 '1 bin,2 txt
end if
Astream.Mode = 3' adModeRead =1
' adModeReadWrite =3
' adModeRecursive =4194304
' adModeShareDenyNone =16
' adModeShareDenyRead =4
' adModeShareDenyWrite =8
' adModeShareExclusive =12
' adModeUnknown =0
' adModeWrite =2
Astream.open
'Astream.CharSet = "GB2312"
'Astream.LoadFromFile(recfilen) '装载文件
'Assp=Astream.size
Astream.Position =0 '装载文件时设置为Assp
'Astream.Writetext tmpstr00,1
if txt then
data=bytes2bstr(data)
Astream.Writetext data,1
else
Astream.Write data
end if
Astream.SaveToFile recfilen,2
Astream.close
end function
'Server.
function downimg(url)
set oXMLHTTP =CreateObject("Microsoft.XMLHTTP")'asp Server.CreateObject("Microsoft.XMLHTTP")
data_got=""
oXMLHTTP.open "GET",url, false
oXMLHTTP.setRequestHeader "Aept-Encoding"," gzip, deflate"
oXMLHTTP.setRequestHeader "User-Agent","Mozilla/4.0 (patible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 2.0.50727)"
oXMLHTTP.send
rtstatus=oXMLHTTP.status
data_got=oXMLHTTP.responsebody
filename=mid(url,InStrRev(url,"/")+1)
if rtstatus=200 then
data_got=oXMLHTTP.responsebody
saveFile data_got,filename
else
data_got=""
end if
set oXMLHTTP =nothing
end function
function bytes2bstr(vin) '二进制转化为汉字
strreturn = ""
for i = 1 to lenb(vin)
thischarcode = ascb(midb(vin,i,1))
if thischarcode < &h80 then
strreturn = strreturn & chr(thischarcode)
else
nextcharcode = ascb(midb(vin,i+1,1))
strreturn = strreturn & chr(clng(thischarcode) &h100 + cint(nextcharcode))
i = i + 1
end if
next
bytes2bstr = strreturn
end function
使用方法
代码如下:
imgurl="http://.163car./UpFile/CarImages/0092/S_b_20051241127326f6uew1s.jpg" '图片
downimg(imgurl)
imgurl="HTTP://login.zydn./news.asp" '文字页面
downimg(imgurl)
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程