#!/bin/python #coding:utf-8 def wget(url,new_name=""): ''' wget封装,需提供下载地址,新文件名参数可省略
#!/bin/python
#coding:utf-8
def wget(url,new_name=""):
'''
wget封装,需提供下载地址,新文件名参数可省略
'''
try:
file_name = url[url.rfind("/")+1:]
if new_name == "":
new_name = file_name
fp = urllib.urlopen(url)
py_ver = sys.version[:3]
if fp.getcode() != 200:
raise NameError,'%s not exist.'%file_name
buf_len = 2048
f = open(new_name,'wb')
size = 0
while 1:
s = fp.read(buf_len)
if not s:
break
f.write(s)
size += len(s)
fp.close()
f.flose()
print "%s success"%url
except Exception,e:
print Exception,":",e
--结束END--
本文标题: python实现Linux命令wget
本文链接: https://www.lsjlt.com/news/190095.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0