Test a Web site with Python

Source: Internet
Author: User

     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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.