Select to view content in your preferred language

Check for broken urls in feature layer table

1296
4
Jump to solution
06-13-2022 05:54 AM
Labels (2)
KateRose
Occasional Contributor

Hello-

I have an AGOL hosted feature layer with about 50 features. Each feature has at least one URL to link to external websites for more information. Is there a tool within AGOL or ArcGIS Pro that will test each URL to make sure they're valid?

Thanks!

0 Kudos
1 Solution

Accepted Solutions
PeterKnoop
MVP Regular Contributor

I'm not aware of a tool in ArcGIS Online or Pro, however, we have a lot of users with this same need in our organization. Enough that we built and shared an ArcGIS Online Notebook that tests URLs in an attribute field in a feature service (hosted feature layer) the user specifies; much like the solution @jcarlson suggested.

Feel free to give it a try:

Check Attribute URLs 

View solution in original post

4 Replies
jcarlson
MVP Esteemed Contributor

You could probably do this with the Python API, combined with the requests module.

from arcgis import GIS
import requests

# connect to portal
gis = GIS('url', 'user', 'password')

# get feature layer
fl = gis.content.get('itemID').layers[0]

# query out to dataframe
df = fl.query(out_fields=['url_field'], as_df=True)

# pull out url field as list
urls = df['url_field'].to_list()

# check each URL in list, print invalid URLs
for u in urls:
    response = requests.get(u)
    
    if response.status_code == 404:
        print(f'{u} not a valid URL')
- Josh Carlson
Kendall County GIS
KateRose
Occasional Contributor

Thanks! I ended up using Peter Knoop's solution below but yours pretty much uses the same steps. I'm a coding novice and his notebook seemed easier for me to follow, but may try this as well to see which fits better in my workflow.

0 Kudos
PeterKnoop
MVP Regular Contributor

I'm not aware of a tool in ArcGIS Online or Pro, however, we have a lot of users with this same need in our organization. Enough that we built and shared an ArcGIS Online Notebook that tests URLs in an attribute field in a feature service (hosted feature layer) the user specifies; much like the solution @jcarlson suggested.

Feel free to give it a try:

Check Attribute URLs 

KateRose
Occasional Contributor

Thanks, Peter! this was super easy to follow for a coding novice like myself and it worked perfectly. One exception: I got an error when trying to run the %%time magic command, so I edited it to %time and it worked that way.

0 Kudos