pcurl 學習 http檔案下載及寫入空裝置檔案執行個體

來源:互聯網
上載者:User

標籤:

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

pcurl 學習 http檔案下載及寫入空裝置檔案執行個體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.