zoukankan      html  css  js  c++  java
  • python 实现文件下载

    直接输入下载地址就行了,但不能下载txt、bat等文本形式,会出现乱码的情况。

    #!/usr/bin/env python
    
    import urllib2
    import sys,os
    
    
    def main(url):
        ext = url[url.rindex("."):]
        filename = url[url.rindex("/")+1:url.rindex(".")]
        folder = os.getcwd()
        try:
            f = urllib2.urlopen(url)
            with open(filename+ext,"wb") as code:
                code.write(f.read())
        except:
            print("parameter error!the url is error?")
            sys.exit(0)
        print("download OK,you can find it in %s\" %folder)
    
    if __name__ == "__main__":
        if len(sys.argv) < 2:
            print("
    	argument error!
    ")
    	print("	Useage: file_download.py https://www.xxoo/hehe.zip")
        else:
            main(sys.argv[1])
    

     求乱码解决方案啊!!

    如: https://smarthosts.googlecode.com/svn/trunk/hosts.bat 

  • 相关阅读:
    cz_health_day07
    cz_health_day06
    mysql索引底层原理
    cz_health_day05
    redis无法获取连接原因分析
    cz_health_day04
    cz_health_day03
    cz_health_day02
    cz_health_day01
    Spring学习
  • 原文地址:https://www.cnblogs.com/tk091/p/3422915.html
Copyright © 2011-2022 走看看