Skip to content

Instantly share code, notes, and snippets.

@miklevin
Created July 16, 2019 19:24
Show Gist options
  • Save miklevin/16e8a4ebafb68a792a70986b155015c0 to your computer and use it in GitHub Desktop.
Save miklevin/16e8a4ebafb68a792a70986b155015c0 to your computer and use it in GitHub Desktop.
Got to clean up a sloppy list of URLs for API-use? You're welcome.
sites = '''
www.google.com
http://www.amazon.com
apple.com
'''.split('\n')[1:-1]
for i, site in enumerate(sites):
if site[:4].lower() != 'http':
sites[i] = 'http://%s' % site
import requests
for i, site in enumerate(sites):
try:
r = requests.get(site)
sites[i] = r.url
except:
sites[i] = "error: %s" % site
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment