Get size of a file before downloading in Python

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

    For a python3 (tested on 3.5) approach I'd recommend:

    with urlopen(file_url) as in_file, open(local_file_address, 'wb') as out_file:
        print(in_file.getheader('Content-Length'))
        out_file.write(response.read())
    

提交回复
热议问题