daily work, we need to test the concurrency of the site, response time, can test these points of third-party software is very more, this is not the focus of this article, We use Python scripts to write a simple piece of code to test the site concurrency and response time . Test the response time of the website test the response time of the webpage, the code is as follows: import threadingimport Urllibfrom time import sleep,ctimedef gethtml (Func,url): try: print ' start request: %s,%s ' % (func, CTime ()) page = urllib.urlopen (URL) html = page.read () print ' receive response:%s,%s ' % (Func,ctime ()) return html except: print ' Error ... ' return []if __name__== ' __main__': url = ' http://image.baidu.com/channel?c=%E7%BE%8E%E5%A5%B3#%E7%BE%8E%E5%A5 %b3 " for i in range (1,11): print '%s : request '%i test = Gethtml (i,url) print '------------------------------------ ----------' Run the program, the results are as follows: type "copyright", "credits" or "License ()" for more information.>>> ================================ restart ============= ===================>>> 1 : requeststart request: 1,sun may  03 13:29:41 2015RECEIVE RESPONSE:1,SUN MAY 03 13:29:41 2015---------- ------------------------------------2 : requeststart request: 2,sun may 03 13:29: 41 2015receive response:2,sun may 03 13:29:42 2015----------------------------- -----------------3 : requeststart request: 3,sun may 03 13:29:42 2015receive response:3,sun may 03 13:29:42 2015------------------------ ----------------------4 : requeststart request: 4,sun may 03 13:29:42 2015receive response:4,sun may 03 13:29:43 2015------------------------ ---------------------- above is a very rough code snippet, but if you write the program's output information to a file and write a corresponding data System Code, we can implement a test page access time code.
This article is from the "Simple New Life" blog, please be sure to keep this source http://857768.blog.51cto.com/847768/1641397
Test a Web site with Python