Get size of a file before downloading in Python

前端 未结 8 1267
名媛妹妹
名媛妹妹 2020-12-02 06:56

I\'m downloading an entire directory from a web server. It works OK, but I can\'t figure how to get the file size before download to compare if it was updated on the server

8条回答
  •  失恋的感觉
    2020-12-02 07:21

    The size of the file is sent as the Content-Length header. Here is how to get it with urllib:

    >>> site = urllib.urlopen("http://python.org")
    >>> meta = site.info()
    >>> print meta.getheaders("Content-Length")
    ['16535']
    >>>
    

提交回复
热议问题