爬虫maizi
来源:互联网 发布:中国社交网络发展历程 编辑:程序博客网 时间:2024/06/05 10:37
#encoding:utf8import _threadimport timeimport requestsfrom lxml import etreeimport reimport sysfrom contextlib import closing# 为线程定义一个函数class ProgressBar(object): def __init__(self, title, count=0.0, run_status=None, fin_status=None, total=100.0, unit='', sep='/', chunk_size=1.0): super(ProgressBar, self).__init__() self.info = "【%s】%s %.2f %s %s %.2f %s" self.title = title self.total = total self.count = count self.chunk_size = chunk_size self.status = run_status or "" self.fin_status = fin_status or " " * len(self.status) self.unit = unit self.seq = sep def __get_info(self): # 【名称】状态 进度 单位 分割线 总数 单位 _info = self.info % (self.title, self.status, self.count/self.chunk_size, self.unit, self.seq, self.total/self.chunk_size, self.unit) return _info def refresh(self, count=1, status=None): self.count += count # if status is not None: self.status = status or self.status end_str = "\r" if self.count >= self.total: end_str = '\n' self.status = status or self.fin_status print(self.__get_info()) print(end=end_str)def print_time(threadName='Thread-1', delay='http://newoss.maiziedu.com/qiniu/1shuozaiqianmiandehua.mp4'): da = {'Referer': 'http://m.maiziedu.com/course/393-4373/', 'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.76 Mobile Safari/537.36'} with closing(requests.get(delay, stream=True,headers=da)) as response: chunk_size = 1024 # 单次请求最大值 content_size = int(response.headers['content-length']) # 内容体总大小 progress = ProgressBar(threadName, total=content_size, unit="KB", chunk_size=chunk_size, run_status="正在下载", fin_status="下载完成") with open('F:\\10\\bsbs\\mai\\'+threadName+'.mp4', "wb") as file: for data in response.iter_content(chunk_size=chunk_size): file.write(data) progress.refresh(count=len(data)) print(threadName+'开始') # yuan = requests.get(delay, headers=da).content # op = open('F:\\10\\bsbs\\mai\\'+threadName+'.mp4', 'wb') # op.write(yuan) # op.close()# 创建两个线程# print_time()try: _thread.start_new_thread(print_time, ("Thread-1",'http://newoss.maiziedu.com/qiniu/1shuozaiqianmiandehua.mp4')) _thread.start_new_thread(print_time, ("Thread-2",'http://newoss.maiziedu.com/qiniu/8lei.mp4'))except: print("Error: unable to start thread")while 1: passprint("Main Finished")
阅读全文
0 0
- 爬虫maizi
- 爬虫
- 爬虫
- 爬虫
- 爬虫
- 爬虫
- 爬虫
- 爬虫
- 爬虫
- 爬虫
- 爬虫
- 爬虫
- 爬虫
- 爬虫
- 爬虫
- 爬虫
- 爬虫
- 爬虫
- linux系统Samba安装配置实现与Windows文件共享
- Android Studio打包
- java运算符优先级
- 基本运算符重载实例
- 使用kubeadm将Kubernetes集群从1.6版本升级到1.7
- 爬虫maizi
- log4j有针对性的将日志输出到不同文件且不重复输出到root中
- Centos Yum error – ImportError: No module named cElementTree
- Spring框架中的各种*Aware接口
- PostMessage和SendMessage
- 前端JS如何获取主域名(根域名)
- JavaScript中的call和apply用法
- jboss规则引擎KIE Drools 6.3.0-高级讲授篇
- 爬虫mm