我正在使用python请求库以多处理方式在“onionurl”下载文件,从tor服务下载大量文件
这就是代码背后的原因
然而,当这些文件下载时,每个文件都会在一两分钟后被删除。由于在流中无法下载,因此不会给出错误,但会返回“关闭文本文件”。这意味着不可能下载托管在这些洋葱服务器上的文件,每个服务器都有几百GB
如果您能帮助解决这个问题,我们将不胜感激
session = requests.session()
session.proxies = {}
session.proxies['http'] = 'socks5h://localhost:9050'
session.proxies['https'] = 'socks5h://localhost:9050'
#print(onionurlforrequest)
url = onionurl
try:
if not os.path.isdir(foldername):
os.makedirs(foldername)
# download the body of response by chunk, not immediately
with session.get(url, stream=True, verify=False, timeout=1000000) as response:
# get the total file size
file_size = int(response.headers.get("Content-Length", 0))
print(file_size)
# get the file name
filename = dataloc
with open(filename, "wb") as text_file:
for chunk in response.iter_content(chunk_size=1024):
text_file.write(chunk)
if (file_size > 1000000):
filesizemb = file_size / 1000000
else:
filesizemb = 1
print("closing text file")
text_file.close()
通过简单地接受连接将终止并编写一个新函数以精确的偏移量恢复下载,解决了这个问题,其原理在这个问题中解释-How to resume file download in Python?
我的代码(警告,混乱):
相关问题 更多 >
编程相关推荐