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

代码如下:



#!/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


AddThis Social Bookmark Button

相关文档(Relevant Entries)
实现URL编码解码的python程序
python资源
使用python为Java项目增加一个预编译脚本[转]
Python Web frameworks, Part 1
Python Web frameworks, Part 2
Plone是什么?
Open Source GIS-Python Laboratory(基于Python的开源GIS项目推荐)
Python连接MySQL
Posted on July 27, 2007 2:22 PM | | | Comments (0) | | TrackBacks (0)

引用地址(TRACKBACKS)
 
TrackBack URL for this entry:
http://www.wujianrong.com/mt-tb.cgi/5773

发布评论(ADD YOUR COMMENTS)
 
感谢您参与评论;发表您的意见时请保持文章的相关性;不相关的或是单纯宣传的内容可能会被删掉。您的E-mail只是用来确认您发表的文章,不会出现在网页上。
Please keep your comments relevant to this blog entry. Email addresses are never displayed, but they are required to confirm your comments.

称呼(Name):      记住我的个人信息(Remember)
邮箱(Email):
网址(URL):
评论(Add your comments):

相关内容
广告计划