我一直在尝试使用Python的请求模块制作一个简单的动画下载器。我使用progressbar2模块跟踪进度。在尝试下载时,我得到的速度是0.x B/s。我假设问题是基于this question选择chunk_size
。但不管区块大小,我都能得到同样微不足道的速度。在
requests
模块(2.18.4),有一个不错的网速为40Mbps。在import os
import requests
import progressbar
from progressbar import *
os.chdir('D:\\anime\\ongoing')
widgets = ['Downloading: ', Percentage(), ' ', Bar(marker='#',left='[',right=']'),
' ', ETA(), FileTransferSpeed()]
url = 'https://lh3.googleusercontent.com/AtkUe87GbrINzTJS_Fj4W08CGqlOg9anwEF7n5-eKXcyS1RsaB8LdzRVaXloiJwiaX2IX1xqUiA=m22?title=(720P%20-%20mp4)Net-juu%20no%20Susume%20Episode%207'
r = requests.get(url,stream=True)
remotesize = r.headers['content-length']
print("Downloading {}.mp4!\n\n".format(url.split('title=')[1]))
pbar = ProgressBar(max_value=int(remotesize),widgets=widgets).start()
i = 0
with open('./tempy/tempy_file.mp4', 'wb') as f:
for chunk in r.iter_content(chunk_size=5*1024*1024):
if chunk:
i = i + len(chunk)
f.write(chunk)
pbar.update(int(i/int(remotesize) * 100))
pbar.finish()
print("Successfully downloaded!\n\n")
不确定这个Github Issue是否已修复。
shutil.copyfileobj(r.raw)
不是我要找的。在根据建议,我尝试使用随机用户代理,如下所示:
^{pr2}$并发送头为r = requests.get(url,stream=True,headers=random_headers())
的请求
然而,这没有什么不同。:(
用“http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_5mb.mp4”中的示例视频进行了尝试。同样的问题依然存在。:/
你有没有试过用你的用户代理和其他Google可能需要的头来填充你的请求头,这样就不会把你标记为机器人,限制你的下载速度?在
所以就像其他人所说的那样,谷歌正在放慢速度。为了克服这个问题,我使用Selenium webdriver下载了以下链接:
好吧,至少我可以用googlechrome的下载程序以尽可能快的速度完全自动化下载。在
因此,如果有人能帮我解决这个问题,请在评论中回复,如果有帮助,我会投赞成票:
以下是指向完整的script的链接。在
相关问题 更多 >
编程相关推荐