Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 操作系统 > Linux > 用python写的一个网页测试工具
【标  题】:用python写的一个网页测试工具
【关键字】:python
【来  源】:http://blog.csdn.net/kunp/archive/2007/04/11/1561094.aspx

用python写的一个网页测试工具

Your Ad Here

写了一个测试网站的脚本,用多线程跑的,每个线程每秒去取一次网页,因为这个脚本用到了线程啊,time,ulrlib这些东西,也许对其他人会有用,贴出来吧。

另外一个原因是,通过这个脚本,发现python的效率真的不错,无论是开发效率还是执行效率。之前完全没用过python的thread和time,一边看python programing,一边写,也就一个小时的功夫,看上去效果还不错。

代码如下:

 


#!/usr/local/bin/python
#FileName = test_Web.py

#get from db
#http://192.168.1.74/spaces/posts/postdetail.aspx?id=
#put into db
#http://192.168.1.74/admin/space/post/post_add.aspx?fid=0&um=300372&v=__VERSION__&title=0&content=hahaasdfasdf

import thread, time, urllib

id_index = 100000
id_count = 20000
id_max = id_index+id_count
i_cnt = 0
time_begin = time.time()
bStop = False

def openurl():
 sock = urllib.urlopen("
http://192.168.1.74/admin/space/post/post_add.aspx?fid=0&um=300372&v=__VERSION__&title=0&content=hahaasdfasdf")
 htmlSource = sock.read()
 #print htmlSource
 sock.close() 
 
def opengeturl(id):
 strUrl = "
http://192.168.1.74/spaces/posts/postdetail.aspx?id=%d" % id
 print strUrl
 sock = urllib.urlopen(strUrl)
 htmlSource = sock.read()
 #print htmlSource
 sock.close() 

def child( myID ):        # this function runs in threads
 while( True ):
  global id_index
  global id_max
  global id_count
  global time_begin
  global bStop
  global i_cnt
  
  if( i_cnt > id_count ):
   now = time.time()
   i_handle_time = now - time_begin
   if( bStop == False ):
    print "%d rows cost %f second" % ( id_count, i_handle_time )
   bStop = True
   break
  #id_index = id_index + 1
  i_cnt = i_cnt + 1
  print "[%d] ==> %d" % (myID, id_index)
  opengeturl(id_index)
  time.sleep(1)

for i in range( 500 ):       # spawn 3 threads
 thread.start_new( child, (i,) )
 
time.sleep(1000000)
print 'Main thread exiting.'        # don't exit too early

 


Linux 指令详解: chmod:【上一篇】
Linux硬盘安装方法:【下一篇】
【相关文章】
  • 最大公约数欧几里德算法及Python实现
  • Ruby 和 python
  • 如何使你的UltraEdit支持Python语法高亮?
  • Python应用:邪恶力量S01E09字幕时间调整
  • 学习Python(1)——流程控制
  • 新的Python 3000视频和幻灯
  • 学习Python(2)——函数
  • 学习Python(3)——List内置方法
  • 学习Python(4)——面向函数编程
  • Python入门
  • 【随机文章】
  • 找出并保护程序的入口
  • 质疑fread()的块方式读取
  • 缓冲区溢出原理及防护
  • Emacs配置点滴
  • 写C++程序要清楚自己的角色(孟岩)
  • CWDM技术在城域网中的应用(2)
  • 监理在信息系统工程中的定位
  • 写Hanoi 塔问题求解过程演示程序未遂
  • 旧题重谈VNC
  • 拦截BT与电驴
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.