Get size of a file before downloading in Python

前端 未结 8 1300
名媛妹妹
名媛妹妹 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:26

    In Python3:

    >>> import urllib.request
    >>> site = urllib.request.urlopen("http://python.org")
    >>> print("FileSize: ", site.length)
    

提交回复
热议问题