python使用多线程不断刷新网页的方法
2015-03-31 10:03
1036 查看
本文实例讲述了python使用多线程不断刷新网页的方法。分享给大家供大家参考。具体如下:
这段代码可以开通过个线程不断刷新指定的页面,可用于刷票,增加网页访问量等等,不用再去按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 //www.jb51.net/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程序设计有所帮助。
您可能感兴趣的文章:
相关文章推荐
- python使用自定义user-agent抓取网页的方法
- 使用JavaScript刷新网页的方法
- Python使用正则表达式抓取网页图片的方法示例
- Python使用Phantomjs截屏网页的方法
- Python开发中爬虫使用代理proxy抓取网页的方法示例
- python使用htmllib分析网页内容的方法
- python多线程模块:threading使用方法(参数传递)
- python爬虫(20)使用真实浏览器打开网页的两种方法
- python 8-1 如何使用多线程,Thread创建线程,执行函数赋值给target//类+函数放在run方法中执行
- python爬虫 使用真实浏览器打开网页的两种方法总结
- Python获取网页指定内容(BeautifulSoup工具的使用方法)
- 使用Python模块webbrowser实现自动打开网页/刷新网页
- [Python]使用shelve方法建立网页书签数据库
- python使用正则表达式分析网页中的图片并进行替换的方法
- python使用正则表达式提取网页URL的方法
- Python3使用requests包抓取并保存网页源码的方法
- Python3使用requests包抓取并保存网页源码的方法
- python回调函数中使用多线程的方法
- Python中的多线程及其基本使用方法