Last active
November 16, 2018 20:15
-
-
Save jjam3774/9145295 to your computer and use it in GitHub Desktop.
Tracks the time for a page to load
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 | |
# -*- coding: utf-8 -*- | |
import urllib2 | |
import os | |
import time | |
def complete_info(): | |
error_file = open('error_file.txt', 'w') | |
for i in open('linkfile'): | |
start = time.time() | |
print("Verifying .. " + i) | |
fetch_url = urllib2.build_opener(urllib2.HTTPHandler(debuglevel=2)) | |
################################### | |
# | |
# DEFINE THE USER AGENT | |
# | |
################################### | |
print "HEADER########################" | |
fetch_url.addheaders = [('User-agent', 'Mozilla/5.0')] | |
results = fetch_url.open(urllib2.Request('http://{0}'.format(i))) | |
print "HEADER########################" | |
print("-"*20) | |
print("COMPLETE..") | |
end = time.time() | |
elapsed = end - start | |
if elapsed > 5: | |
print "PAGE TOOK LONGER THAN 5 SECS TO LOAD.......RESULTS ADDED TO error_file.txt" | |
error_file.write("#"*50) | |
error_file.write("\n" + str(results.info())) | |
error_file.write("#"*50) | |
time.sleep(1) | |
time.sleep(1) | |
error_file.close() | |
def main(): | |
complete_info() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment