473,402 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

timing a web response using urllib.urlopen??

hi all,

python newbie alert! i'm trying to open an array of websites, timing each
site's response time (how may seconds until a response)

if someone could point me in the right direction on accomplishing the
timer part of the this application, i'd appreciate it.

thanks in advance
Jul 18 '05 #1
3 4010
MC******@seminolecountyfl.gov:
i'm trying to open an array of websites, timing each
site's response time (how may seconds until a response)

if someone could point me in the right direction on accomplishing the
timer part of the this application, i'd appreciate it.


class timer:
def __init__(self,name,level=0,parms=""):
self.name = name
self.parms = parms
self.starttime = time.time()

def report(self):
elapsed = time.time() - self.starttime
timefile = open("your filename here", 'a')
print >>timefile, "%s\t%f\t%s" % (self.name, \
elapsed, self.parms)
timefile.close()

timer = new timer("eggs")
# Do something that takes time
timer.report()

name: in my case identified the database query that was executed
repeatedly.
parms: the parameters of a particular execution of the query.

I imported the output in a PostgreSQL database table to query the data.

create table timer(
name varchar,
elapsed float,
parms varchar
);

\copy timer from 'timefile.txt'

select name, count(elapsed), sum(elapsed)
from timer
group by name
order by sum(elapsed) desc;

--
René Pijlman
Jul 18 '05 #2
Rene Pijlman:
self.starttime = time.time()


This requires

import time

of course.

--
René Pijlman
Jul 18 '05 #3
| i'm trying to open an array of websites,
| timing each site's response time
| ( how may seconds until a response )
|
| if someone could point me in the right direction
| on accomplishing the timer part of the this application,
| i'd appreciate it.

'''
NewsGroup .... comp.lang.python
Date ......... 2003-04-30
Posted_By .... kkennedy
Edited_By .... Stanley C. Kitching
'''

from urllib import urlopen

import sys
import time

print '\n ' , sys.argv[ 0 ] , '\n'

list_urls = [ 'http://www.python.org' ,
'http://www.ibm.com' ,
'http://www.microsoft.com' ,
'http://www.sun.com' , ]

for this_url in list_urls :

start = time.time()

doc = urlopen( this_url ).read()

end = time.time()

print " %0.2f .... %s" % ( end - start , this_url )

#
# ------------------------------------------------------------
#
# Output ....
#
url_open_test.py

2.64 .... http://www.python.org
1.10 .... http://www.ibm.com
0.71 .... http://www.microsoft.com
0.66 .... http://www.sun.com

--
Cousin Stanley
Human Being
Phoenix, Arizona

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Richard Shea | last post by:
Hi - I'm new to Python. I've been trying to use URLLIB and the 'tidy' function (part of the mx.tidy package). There's one thing I'm having real difficulties understanding. When I did this ... ...
11
by: Pater Maximus | last post by:
I am trying to implement the recipe listed at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/211886 However, I can not get to first base. When I try to run import urllib...
0
by: Pieter Edelman | last post by:
Hi all, I'm trying to submit some data using a POST request to a HTTP server with BASIC authentication with python, but I can't get it to work. Since it's driving me completely nuts, so here's...
0
by: Chris | last post by:
hello, I have an odd behaviour. I try to download some files connected to a specific webpage (e.g. all stylesheets) with urllib2.urlopen(x) This seems to hang on the 2nd file or so. Doing the...
11
by: Johnny Lee | last post by:
Hi, I was using urllib to grab urls from web. here is the work flow of my program: 1. Get base url and max number of urls from user 2. Call filter to validate the base url 3. Read the source...
6
by: JabaPyth | last post by:
Hello, I'm trying to use the urllib module, but when i try urllib.urlopen, it gives me a socket error: >>import urllib >>print urllib.urlopen('http://www.google.com/').read() Traceback (most...
1
by: onceuponapriori | last post by:
Greetings gents. I'm a Railser working on a django app that needs to do some scraping to gather its data. I need to programatically access a site that requires a username and password. Once I...
4
by: kgrafals | last post by:
Hi, I'm just trying to read from a webpage with urllib but I'm getting IOErrors. This is my code: import urllib sock = urllib.urlopen("http://www.google.com/") and this is the error:
1
by: John Nagle | last post by:
If you try to open a password protected page with "urllib.urlopen()", you get "Enter username for EnterPassword at example.com:" on standard output, followed by a read for input! This seems to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.