"Simon Wigzell" <si**********@shaw.cawrote in message
news:X2A7j.947$ox1.719@pd7urf3no...
I have inherited a database driven website that comes with a table of
image
links. The images are scattered all of the internet and there are
thousands
of them. I would like to write an asp script to just run through the table
and download every link by it's URL. I thought I had id by faking a form
with the "File" element and loading it with all the URLs. Would have
worked
except you cannot preload the "File" element. As I understand it, with the
"File" element you aren't actually loading the file name into it but the
actual file.
Anyway, seems to me this should be possible.
How about a VBScript instead?
It could be ocnverted to ASP if you want.
Watch for word-wrap.
Save it as "fetches.vbs";
create a file named "fetches.txt" with a list of URLs;
double-click on "fetches.vbs" to run it via WScript.exe;
each URL will be downloaded into the "fetches" subfolder;
the filename is the URL without the domain and "_" were "/";
"fetches.log" will summarize the success or failure of each.
<< "fetches.vbs" >>
Option Explicit
'****
'* Fetch a list of URLs per "cTXT" into subfolder "cFOL".
'* Log the activity into "cLOG".
'****
'*
'* Declare Constants
'*
Const cVBS = "fetches.vbs"
Const cTXT = "fetches.txt"
Const cLOG = "fetches.log"
Const cFOL = "fetches\"
'*
'* Declare Variables
'*
Dim strDIR
strDIR = WScript.ScriptFullName
strDIR = Left(strDIR,InStrRev(strDIR,"\"))
Dim arrOTF
Dim intOTF
Dim strOTF
Dim strOUT
Dim intURL
intURL = 0
Dim strPAG
Dim strURL
'*
'* Declare Objects
'*
Dim objCTF
Dim objFSO
Dim objOTF
'*
'* Started
'*
MsgBox "Started.",vbInformation,cVBS
'*
'* Assign Objects
'*
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objCTF = objFSO.CreateTextFile(strDIR & cLOG,True)
objCTF.WriteLine("* Started.")
If Not objFSO.FileExists(strDIR & cTXT) Then
objCTF.WriteLine("* Failed!")
WScript.Quit
End If
Set objOTF = objFSO.OpenTextFile(strDIR & cTXT,1)
'*
'* Create Folder
'*
If Not objFSO.FolderExists(strDIR & cFOL) Then
objFSO.CreateFolder(strDIR & cFOL)
End If
'*
'* Fetch URLs
'*
strOTF = objOTF.ReadAll
arrOTF = Split(strOTF,vbCrLf)
For intOTF = 0 To UBound(arrOTF)
strURL = arrOTF(intOTF)
If Left(strURL,4) = "http" Then
intURL = intURL + 1
strPAG = strURL
strPAG = Mid(strPAG,InStr(strPAG,"//")+2)
strPAG = Mid(strPAG,InStr(strPAG,"/")+1)
strPAG = Replace(strPAG,"/","_")
strOUT = strDIR & cFOL & strPAG
If Fetch(strURL,strOUT) Then
objCTF.WriteLine("+ " & strURL)
Else
objCTF.WriteLine("- " & strURL)
End If
End If
Next
'*
'* Destroy Objects
'*
Set objOTF = Nothing
objCTF.WriteLine("# URLs = " & FormatNumber(intURL,0))
objCTF.WriteLine("* Finished.")
Set objCTF = Nothing
Set objFSO = Nothing
'*
'* Finished
'*
MsgBox "Finished.",vbInformation,cVBS
Function Fetch(xURL,xOUT)
On Error Resume Next
Err.Clear
Dim b
With CreateObject("Microsoft.XMLHTTP")
.Open "GET",xURL,False
.Send
b = .ResponseBody
If Err.Number <0 Or .Status <200 Then
Fetch = False
Exit Function
End If
End With
With CreateObject("ADODB.Stream")
.Type = 1
.Open
.Write b
.SaveToFile xOUT,2
End With
Fetch = Err.Number = 0
End Function
<< Example "fetches.txt" >>
http://www.google.com/intl/en_ALL/images/logo.gif http://images.google.com/intl/en_ALL.../images_hp.gif http://www.google.com/intl/en_us/images/maps_logo.gif http://news.google.com/images/news.gif http://www.google.com/intl/en_us/images/hp0.gif https://mail.google.com/mail/help/images/logo.gif
<< Example "fetches.log" >>
* Started.
+
http://www.google.com/intl/en_ALL/images/logo.gif
+
http://images.google.com/intl/en_ALL.../images_hp.gif
+
http://www.google.com/intl/en_us/images/maps_logo.gif
+
http://news.google.com/images/news.gif
+
http://www.google.com/intl/en_us/images/hp0.gif
+
https://mail.google.com/mail/help/images/logo.gif
# URLs = 6
* Finished.
<< Example contents of sunfolder "fetches\" >>
intl_en_ALL_images_logo.gif
intl_en_ALL_images_images_hp.gif
intl_en_us_images_maps_logo.gif
images_news.gif
intl_en_us_images_hp0.gif
mail_help_images_logo.gif