Skip to content

Instantly share code, notes, and snippets.

@sudokode
Created October 15, 2016 18:17
Show Gist options
  • Save sudokode/414930a9188d2550bc27b98b0008f87d to your computer and use it in GitHub Desktop.
Save sudokode/414930a9188d2550bc27b98b0008f87d to your computer and use it in GitHub Desktop.
content-type in python
#!/usr/bin/env python3
import sys
import re
import requests as r
urls = sys.argv[1:]
for url in urls:
if not re.match('^http(s)?://', url):
url = 'http://' + url
response = r.get(url, allow_redirects=True)
if response:
if response.headers['content-type']:
print('{} is {}'.format(url, response.headers['content-type']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment