Я загружаю весь каталог с веб-сервера. Он работает нормально, но я не могу понять, как получить размер файла перед загрузкой для сравнения, если он был обновлен на сервере или нет. Можно ли это сделать, как если бы я загружал файл с FTP-сервера?
import urllib
import re
url = "http://www.someurl.com"
# Download the page locally
f = urllib.urlopen(url)
html = f.read()
f.close()
f = open ("temp.htm", "w")
f.write (html)
f.close()
# List only the .TXT / .ZIP files
fnames = re.findall('^.*<a href="(\w+(?:\.txt|.zip)?)".*$', html, re.MULTILINE)
for fname in fnames:
print fname, "..."
f = urllib.urlopen(url + "/" + fname)
#### Here I want to check the filesize to download or not ####
file = f.read()
f.close()
f = open (fname, "w")
f.write (file)
f.close()
@Jon: Спасибо за ваш быстрый ответ. Он работает, но размер файла на веб-сервере немного меньше, чем размер файла загруженного файла.
Примеры:
Local Size Server Size
2.223.533 2.115.516
664.603 662.121
Это имеет какое-либо отношение к преобразованию CR/LF?