Python使用urllib2模块实现断点续传下载的方法
作者:RobinTang 时间:2021-12-27 05:20:01
本文实例讲述了Python使用urllib2模块实现断点续传下载的方法。分享给大家供大家参考。具体分析如下:
在使用HTTP协议进行下载的时候只需要在头上设置一下Range的范围就可以进行断点续传下载,当然,首先服务器需要支持断点续传。
利用Python的urllib2模块完成断点续传下载的例子:
#!/usr/bin/python
# -*- coding: UTF-8 -*
'''
Created on 2013-04-15
Created by RobinTang
A demo for Resuming Transfer
'''
import urllib2
req = urllib2.Request('http://www.python.org/')
req.add_header('Range', 'bytes=0-20')
# set the range, from 0byte to 19byte, 20bytes len
res = urllib2.urlopen(req)
data = res.read()
print data
print '---------'
print 'len:%d'%len(data)
希望本文所述对大家的Python程序设计有所帮助。
标签:Python,urllib2,下载
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python+Appium新手教程
2022-12-01 04:12:44
![](https://img.aspxhome.com/file/2023/4/77904_0s.png)
php版银联支付接口开发简明教程
2023-11-24 00:27:41
Python爬虫实现百度图片自动下载
2021-07-12 22:42:56
![](https://img.aspxhome.com/file/2023/3/65423_0s.png)
XML教程:什么是XML及XML和HTML的区别
2008-09-05 17:21:00
Python中的 any() 函数和 all() 函数
2023-05-05 08:38:50
Javascript实现通过选择周数显示开始日和结束日的实现代码
2023-08-23 13:44:52
Python基础之模块详解
2023-02-24 23:23:52
![](https://img.aspxhome.com/file/2023/2/68432_0s.png)
使用python 获取进程pid号的方法
2023-06-11 21:25:52
asp 删除数据并同时删除图片的代码
2011-02-28 10:39:00
sublime text配置node.js调试(图文教程)
2023-07-04 14:07:57
![](https://img.aspxhome.com/file/2023/8/55898_0s.png)
go语言发送smtp邮件的实现示例
2023-06-20 06:59:14
![](https://img.aspxhome.com/file/2023/7/72727_0s.png)
Python使用captcha制作验证码的实现示例
2023-04-16 00:49:35
![](https://img.aspxhome.com/file/2023/3/75113_0s.png)
Python+Pygame编写一个Pong游戏
2023-08-04 15:58:31
![](https://img.aspxhome.com/file/2023/3/61983_0s.png)
Golang优雅保持main函数不退出的办法
2023-07-12 21:15:54
实例讲解PHP验证邮箱是否合格
2023-11-22 07:05:53
![](https://img.aspxhome.com/file/2023/8/88298_0s.png)
Zen Coding: 一种快速编写HTML/CSS代码[译]
2009-12-16 12:53:00
![](https://img.aspxhome.com/file/UploadPic/200912/16/aptana-proj-structure-19s.png)
详解Python 使用 selenium 进行自动化测试或者协助日常工作
2023-09-05 03:44:19
![](https://img.aspxhome.com/file/2023/1/86231_0s.png)
thinkphp的URL路由规则与配置实例
2023-11-16 02:58:57
Python处理PPT文件的实用知识点总结
2021-04-26 04:11:10
SQL Server 安装出错:以前的某个程序安装已在安装计算机上创建挂起的文件操作
2010-02-23 14:48:00