Created
April 21, 2014 22:21
-
-
Save richarvey/11158596 to your computer and use it in GitHub Desktop.
cache-tester
This file contains hidden or 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
#!/usr/bin/python | |
import urllib2, httplib, sys | |
from BeautifulSoup import BeautifulSoup | |
site = "<YOUR URL>" | |
page = urllib2.urlopen('http://' + site) | |
soup = BeautifulSoup(page) | |
tags=soup.findAll('img') | |
print "\nChecking Images" | |
print "===============\n" | |
for tag in tags: | |
asset = tag['src'] | |
connection = httplib.HTTPConnection(site) | |
connection.request("HEAD", asset) | |
response = connection.getresponse() | |
cachecontrol = response.getheader('cache-control') | |
print '%100s : %20s' % (asset, cachecontrol) | |
tags=soup.findAll('link') | |
print "\nChecking CSS" | |
print "===============\n" | |
for tag in tags: | |
if "css" in tag['href'] or "CSS" in tag['href']: | |
asset = tag['href'] | |
connection = httplib.HTTPConnection(site) | |
connection.request("HEAD", asset) | |
response = connection.getresponse() | |
print '%100s : %20s' % (asset, cachecontrol) | |
tags=soup.findAll('script') | |
print "\nChecking JS" | |
print "===============\n" | |
for tag in tags: | |
try: | |
asset = tag['src'] | |
except: | |
print "%100s" % ("Skipping asset") | |
else: | |
connection = httplib.HTTPConnection(site) | |
connection.request("HEAD", asset) | |
response = connection.getresponse() | |
print '%100s : %20s' % (asset, cachecontrol) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment