Created
September 18, 2011 13:52
-
-
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.
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/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) |
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
How do I get "Waiting Time" as given by Network Profiler in the Browsers?