Apr-16-2022, 01:45 PM
(Apr-16-2022, 12:36 PM)kucingkembar Wrote: but somehow does not work at a file on the internet,For internet need something like Requests .
The HEAD request has info about
content-length
.The headers dos not always have true size,so can use
stream=True
to get only response header when download(not whole response body)import requests url = 'https://www.google.co.id/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png' response = requests.get(url, stream=True).headers['Content-length'] print(response)
Output:5969
To download image it would be like this.import requests img = requests.get(url) with open('logo.png', 'wb') as f: f.write(img.content)Some tips about your code,
import
should always first in code.Look into
f-string
.>>> image_name = 'logo.png' >>> stat = 200 >>> # print(image_name + " exist, with size : " + str(statinfo.st_size)) >>> # Become >>> print(f'{image_name} exist, with size: {stat}kb') logo.png exist, with size: 200kb