Created
July 16, 2019 19:24
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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