zoukankan      html  css  js  c++  java
  • pcurl 学习 http文件下载及写入空设备文件实例

    import pycurl

    import sys

    import os

    import random

    import string

    import time

    class Transaction(object):    

      def __init__(self):        

        pass

         def run(self):        

        c = pycurl.Curl()        

        f=open(os.devnull, 'wb')        

        c.setopt(c.URL,'http://localhost/GeeHP5M1080P.mp4')        

        c.setopt(c.WRITEDATA,f)  #write download content to dev null      

        c.setopt(c.HTTPHEADER,["User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)",                

            "Accept: */*",                 "Range: bytes=0-",                 "GetContentFeatures.DLNA.ORG: 1",                 "Pragma: getIfoFileURI.dlna.org",                   "Accept-Language: zh-CN",                 "Accept-Encoding: gzip, deflate",                 "DNT: 1",                 "Host: {Host}"])        

         #c.setopt(c.BUFFERSIZE,655360)        

        c.setopt(c.LOW_SPEED_LIMIT,655360)        

        #c.setopt(c.MAX_RECV_SPEED_LARGE, 10485760)        

        #c.setopt(c.PROGRESSFUNCTION,self.progress)        

        c.setopt(c.FOLLOWLOCATION,1)        

        c.setopt(c.MAXREDIRS,5)        

        c.setopt(c.VERBOSE,1)        

        c.setopt(c.NOPROGRESS, 0)        

        c.perform()                

          http_code=c.getinfo(c.HTTP_CODE)        

          http_conn_time=c.getinfo(c.CONNECT_TIME)        

          http_pre_tran=c.getinfo(c.PRETRANSFER_TIME)        

          http_start_tran=c.getinfo(c.STARTTRANSFER_TIME)        

          http_total_time=c.getinfo(c.TOTAL_TIME)        

          http_size=c.getinfo(c.SIZE_DOWNLOAD)        

          http_rate=c.getinfo(c.SPEED_DOWNLOAD)        

        #print "http_code: %d"%(http_code)        

        #print "http_conn_time: %d"%(http_conn_time)        

        #print "http_pre_tran: %f"%(http_pre_tran)        

          #print "http_start_tran: %f"%(http_start_tran)        

        #print "http_total_time: %f"%(http_total_time)        

        #print "http_size: %f"%(http_size)        

        #print "http_rate: %f"%(http_rate)       

    if __name__ == '__main__':    

      trans = Transaction()    

      trans.run()

  • 相关阅读:
    八张图读懂未来“互联网+”的六大趋势
    跑一段代码遍历所有汉字
    PHP业务逻辑层和数据访问层设计
    漫谈社区PHP 业务开发
    以Apache服务器、php语言为例 详解动态网站的访问过程
    sublime text
    《产品经理的20堂必修课》
    检测文件是否有bom头
    利用开源框架Volley来下载文本和图片。
    往SD卡中写文件的方法。
  • 原文地址:https://www.cnblogs.com/saryli/p/4254025.html
Copyright © 2011-2022 走看看