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

  • 相关阅读:
    [Tips]git cannot lock ref
    [BUG]Git Sever搭建与相关错误处理
    [Tips]matplotlib 命令行画图保存
    [Tips]Torch功能点记录
    5G元年教育产业再出发 科技赋能的“风口与风险”仍待明晰
    Adobe逆天AI黑科技:美颜照克星,秒还原PS照片
    计算机算法能听声音绘制人脸
    2019 CESA,智能座舱越来越“懂你”
    谷歌首席决策科学家:AI难免犯错,唯有人类可以悬崖勒马
    百度:如何将AI进行到底?
  • 原文地址:https://www.cnblogs.com/saryli/p/4254025.html
Copyright © 2011-2022 走看看