Thank you so much! Saved me a lot of trouble. By the way, if anyone wants a python script to automatically check the urls and add /deleted if they 404, here:
import csv
import requests
def check_url(url):
try:
response = requests.head(url)
return response.status_code != 404
except:
return False
with open('YOUR_FILE.csv', mode='r') as csv_file, open('updated_urls.csv', mode='w', newline='') as updated_csv_file:
csv_reader = csv.DictReader(csv_file)
fieldnames = csv_reader.fieldnames
csv_writer = csv.DictWriter(updated_csv_file, fieldnames=fieldnames)
csv_writer.writeheader()
for row in csv_reader:
url = row['Image Src']
if not check_url(url):
new_url = url.replace('/products/', '/deleted/products/')
if check_url(new_url):
print(f"{url} is invalid, but {new_url} is valid")
row['Image Src'] = new_url
else:
print(f"{url} and {new_url} are both invalid")
csv_writer.writerow(row)
You need to have Python and requests installed, put this script into the same folder as your CSV, change YOUR_FILE.csv to the correct file name and run it. Takes a bit of time to complete.