Batch Download from Links in Attribute Table

201
3
a month ago
BradParkinson
New Contributor

I'm trying to implement some LiDAR data into my ArcGIS Pro work. The data I want to access is packaged into tiles, each hosted as their own feature in a single layer. These tiles contain a hyperlinked URL in the attribute table, which allow me to download the corresponding .laz files.

 

I want to download several hundred of these files, and I think Python would be a good choice to automate the downloading for me. Does anybody have pointers, tips, etc? I've seen mention of a 'for loop', would that be appropriate for this type of task?

 Screenshot 2024-04-22 141455.png

3 Replies
RhettZufelt
MVP Frequent Contributor

would it be possible to supply the complete Download_L URL for testing?

R_

BradParkinson
New Contributor
0 Kudos
RhettZufelt
MVP Frequent Contributor

Pretty basic, no error testing, but should get you started.

I do check to make sure the file hasn't already been downloaded:

 

 

import arcpy, os, urllib.request

fc = r'\\servername\sharename\folder\Pro_Test_map.gdb\TestFC'  # input feature class with URL attribute

outfold = r'C:\Users\myusername\Desktop\tmp'              #location to save laz files

with arcpy.da.SearchCursor(fc, ['Download_L']) as cursor:    # establish search cursor with "Download_L" as url field
    for row in cursor:                                 # iterate trough list of files
        infile = os.path.basename(row[0])              # get existing filename
        outfile = outfold + os.sep + infile            # set new filename/location                             
        if not os.path.exists(outfile):                # check to make sure file doesn't already exist
            print("downloading - " + outfile)
            urllib.request.urlretrieve(row[0], outfile)  # download the file
        else: print(outfile + '   already exists')

 

 

R_