我正在从Web服务器下载整个目录.它工作正常,但我无法想象如何在下载之前获取文件大小以进行比较,如果它在服务器上更新了.这可以像我从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) …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用urllib2 http客户端在python中创建下载进度条.我查看了API(以及谷歌),似乎urllib2不允许您注册进度挂钩.但是旧版已弃用的urllib确实具有此功能.
有谁知道如何使用urllib2创建进度条或报告钩子?或者是否有其他一些黑客可以获得类似的功能?