Code for downloading and saving pictures with ASP VBS XMLHTTP Adodbstream application Tips

Source: Internet
Author: User
Function:

Copy Code code as follows:

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) ' Loading file
' Assp=astream.size
astream.position = 0 ' set to ASSP when loading files
' 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 "accept-encoding", "gzip, deflate"
Oxmlhttp.setrequestheader "User-agent", "mozilla/4.0" (compatible; 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) ' binary conversion to Chinese characters
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

How to use:
Copy Code code as follows:

Imgurl= "http://www.163car.com/UpFile/CarImages/0092/S_b_20051241127326f6uew1s.jpg" pictures
Downimg (Imgurl)
Imgurl= "HTTP://login.zydn.net/news.asp" text page
Downimg (Imgurl)
Save the code as a VBS file and run it without the need for IIS.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.