HOW TO

List URLs from text fields in ArcGIS Pro using ArcPy

Last Published: August 30, 2024

Summary

In ArcGIS Pro, efficiently downloading data from every linked item listed in a table, where each item's URL is stored in a specific field, is possible. The SearchCursor function can be used to return rows of attribute values from a feature class or table. By iterating through the rows, the URLs can be extracted and listed from text fields containing only URL links, such as those starting with 'https' or 'www'. This approach provides streamlined data processing and facilitates further operations involving the extracted URLs. This article describes the workflow to list the URLs from the text fields using ArcPy.

The URLs in a text field of a stand-alone table in ArcGIS Pro

Procedure

Note: 
This workflow requires a full script to run in the ArcGIS Pro Python window. The indents must be retained as portrayed in the code block.
  1. Open the project containing the URLs in ArcGIS Pro.
  2. Open the Python window. Refer to ArcGIS Pro: Python window for more information.
  3. Run the script below.
    1. To set the path of the stand-alone table:
import arcpy

table = r"<pathName>"
  1. To fetch and store information about the field containing the URLs:
url_field = "URL"
  1. To create a list to store the URLs:
url_list = []
  1. To search the records, identify, and retrieve the URLs based on their prefixes using SearchCursor and startswith():
with arcpy.da.SearchCursor(table, [url_field]) as cursor:
    for row in cursor:
        url = row[0] 
        if url is not None:
            if url.startswith('https') or url.startswith('www'):
                url_list.append(url)
            else:
                pass 
  1. To print the results:
for url in url_list:
    print(url)

The code block below demonstrates the full working script.

import arcpy

table = r" C:\Training\StartAnalytics\Data\FarmAnalysis.gdb\FarmMarket"

url_field = "URL"

url_list = []

with arcpy.da.SearchCursor(table, [url_field]) as cursor:
    for row in cursor:
        url = row[0] 
        if url is not None:
            if url.startswith('https') or url.startswith('www'):
                url_list.append(url)
            else:
                pass 

for url in url_list:
    print(url)

The image below shows the URLs printed in the Python window.

The URLs printed in the Python window

Article ID: 000033279

Software:
  • ArcGIS Pro 3 1
  • ArcGIS Pro 3 3
  • ArcGIS Pro 3 2

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options