Skip to content

Instantly share code, notes, and snippets.

@skwashd
Created September 18, 2011 13:52
Show Gist options
  • Save skwashd/1225092 to your computer and use it in GitHub Desktop.
Save skwashd/1225092 to your computer and use it in GitHub Desktop.
Python script to check if a remote site is up and measure the load time. Ideal for running from cron.
#!/usr/bin/env python
#
# Check if a website is loading and contains a nominated string.
#
# Usage:
# site-up.py http://example.com/ 'text to search for'
#
import errno
import re
import sys
import time
import urllib
url = sys.argv[1]
search = sys.argv[2]
start = 0
end = 0;
f = urllib.urlopen(url)
start = time.time()
page = f.read()
end = time.time()
f.close()
err = ''
exitCode = 0
matches = re.search(search, page)
if matches is None:
err = "\nSearch string not found"
exitCode = errno.ENOENT
print 'Page loaded in {time}s.{error}'.format(time=round(end-start, 2), error=err)
sys.exit(exitCode)
@aeroaks
Copy link

aeroaks commented Jun 21, 2014

How do I get "Waiting Time" as given by Network Profiler in the Browsers?

@tuwid
Copy link

tuwid commented Nov 15, 2014

the results are inaccurate as a page has many other components that impact load including here js,css,images and other things

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment