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()

  • 相关阅读:
    Django基础六之ORM中的锁和事务
    Django学习之model进阶
    Django基础八之cookie和session
    Django基础五之django模型层(二)多表操作
    Django基础五之django模型层(一)单表操作
    Django基础四之模板系统
    webpack最佳入门实践系列(4)
    webpack最佳入门实践系列(3)
    webpack最佳入门实践系列(2)
    webpack最佳入门实践系列(1)
  • 原文地址:https://www.cnblogs.com/saryli/p/4254025.html
Copyright © 2011-2022 走看看