Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loopimg link and downlosd zip file 1

sal21

Programmer
Apr 26, 2004
456
IT
based this link:


how to loop all link, and download the related zip file based

indirizzario regione name of regione

save the zip file Abruzzo.zip, in c:\mydir\

for example

note:
this is my last code for test:

Sub testit()

Dim httpObject As Object
Set httpObject = CreateObject("MSXML2.XMLHTTP")
Dim doc As Object
Set doc = CreateObject("htmlfile")
Dim links As Variant
Dim L As Variant

With httpObject

.Open "GET", "https://www.anncsu.gov.it/it/consul...di-ai-servizi-di-dowload-massivo-in-Open-data", False
.send

Do Until httpObject.ReadyState = 4
Loop

doc.body.innerhtml = .responseText

Debug.Print (doc.body.innerhtml)

Set links = doc.getElementsByTagName("a")

For Each L In links

Debug.Print L.href

Next L

End With

End Sub
 
Last edited:
Rich (BB code):
Option Explicit

Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

Sub testit()

    Dim httpObject As Object
    Set httpObject = CreateObject("MSXML2.XMLHTTP")
    Dim doc As Object
    Set doc = CreateObject("htmlfile")
    Dim links As Variant
    Dim L As Variant
    Dim myfilename As String
    
    With httpObject
    
        .Open "GET", "https://www.anncsu.gov.it/it/consultazione-dellarchivio/open-data/Accedi-ai-servizi-di-dowload-massivo-in-Open-data", False
        .send
    
        Do Until httpObject.ReadyState = 4
        Loop

        doc.body.innerhtml = .responseText

        'Debug.Print (doc.body.innerhtml)

        Set links = doc.getElementsByTagName("a")
    
        For Each L In links 'can be a lengthy process, so might want to put in some sort of acrtivity or progreess indicatior
            If InStr(L.href, "getds.php?") > 0 Then
                myfilename = "d:\downloads\deleteme\" & Right(L.Search, Len(L.Search) - 1) & ".zip"
                Debug.Print "Downloading to " & myfilename 'L.href
                URLDownloadToFile 0, L.href, myfilename, 0, 0
            End If
        Next L

    End With

End Sub
 
STRONGM, AS USUAL TKS FOR CODE! Work perfect!

only a dubt...
should i check, if it is possible, if the file i am downloading is newer than the one i downloaded before? to avoid wasting time...
 
Last edited:
I think we've Portishead pointed out that HTTP doesn't support timestamps, so not sure how you'd check that.

What you could do is check the timestamp of the contents of the zip file being downloaded against the timestamp of the contents of any existing zip file that is about to be replaced..

So, sure try that
 

Part and Inventory Search

Sponsor

Back
Top