"Simon Wigzell" <si**********@s haw.cawrote in message
news:X2A7j.947$ ox1.719@pd7urf3 no...
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.vb s";
create a file named "fetches.tx t" with a list of URLs;
double-click on "fetches.vb s" 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.lo g" will summarize the success or failure of each.
<< "fetches.vb s" >>
Option Explicit
'****
'* Fetch a list of URLs per "cTXT" into subfolder "cFOL".
'* Log the activity into "cLOG".
'****
'*
'* Declare Constants
'*
Const cVBS = "fetches.vb s"
Const cTXT = "fetches.tx t"
Const cLOG = "fetches.lo g"
Const cFOL = "fetches\"
'*
'* Declare Variables
'*
Dim strDIR
strDIR = WScript.ScriptF ullName
strDIR = Left(strDIR,InS trRev(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.",vbIn formation,cVBS
'*
'* Assign Objects
'*
Set objFSO = CreateObject("S cripting.FileSy stemObject")
Set objCTF = objFSO.CreateTe xtFile(strDIR & cLOG,True)
objCTF.WriteLin e("* Started.")
If Not objFSO.FileExis ts(strDIR & cTXT) Then
objCTF.WriteLin e("* Failed!")
WScript.Quit
End If
Set objOTF = objFSO.OpenText File(strDIR & cTXT,1)
'*
'* Create Folder
'*
If Not objFSO.FolderEx ists(strDIR & cFOL) Then
objFSO.CreateFo lder(strDIR & cFOL)
End If
'*
'* Fetch URLs
'*
strOTF = objOTF.ReadAll
arrOTF = Split(strOTF,vb CrLf)
For intOTF = 0 To UBound(arrOTF)
strURL = arrOTF(intOTF)
If Left(strURL,4) = "http" Then
intURL = intURL + 1
strPAG = strURL
strPAG = Mid(strPAG,InSt r(strPAG,"//")+2)
strPAG = Mid(strPAG,InSt r(strPAG,"/")+1)
strPAG = Replace(strPAG, "/","_")
strOUT = strDIR & cFOL & strPAG
If Fetch(strURL,st rOUT) Then
objCTF.WriteLin e("+ " & strURL)
Else
objCTF.WriteLin e("- " & strURL)
End If
End If
Next
'*
'* Destroy Objects
'*
Set objOTF = Nothing
objCTF.WriteLin e("# URLs = " & FormatNumber(in tURL,0))
objCTF.WriteLin e("* Finished.")
Set objCTF = Nothing
Set objFSO = Nothing
'*
'* Finished
'*
MsgBox "Finished.",vbI nformation,cVBS
Function Fetch(xURL,xOUT )
On Error Resume Next
Err.Clear
Dim b
With CreateObject("M icrosoft.XMLHTT P")
.Open "GET",xURL,Fals e
.Send
b = .ResponseBody
If Err.Number <0 Or .Status <200 Then
Fetch = False
Exit Function
End If
End With
With CreateObject("A DODB.Stream")
.Type = 1
.Open
.Write b
.SaveToFile xOUT,2
End With
Fetch = Err.Number = 0
End Function
<< Example "fetches.tx t" >>
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.lo g" >>
* 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_ima ges_logo.gif
intl_en_ALL_ima ges_images_hp.g if
intl_en_us_imag es_maps_logo.gi f
images_news.gif
intl_en_us_imag es_hp0.gif
mail_help_image s_logo.gif