Python中文
首页
教程
问答
标签
搜索
登录
注册
Python请求modu下载速度低得离谱
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<h2>问题:</h2> <p>我一直在尝试使用Python的请求模块制作一个简单的动画下载器。我使用progressbar2模块跟踪进度。在尝试下载时,我得到的速度是0.x B/s。我假设问题是基于<a href="https://stackoverflow.com/questions/37571466/increase-download-speed-of-requests">this question</a>选择<code>chunk_size</code>。但不管区块大小,我都能得到同样微不足道的速度。在</p> <h2>规格和信息:</h2> <ol> <li>我使用的是windows10,python3.5,最新的<code>requests</code>模块(2.18.4),有一个不错的网速为40Mbps。在</li> <li>我可以通过浏览器(Chrome)从链接下载该文件,并且免费下载 下载管理器</em>大约1分钟。在</li> <li>链接是完美的工作,我没有防火墙冲突。在</li> </ol> <h2>代码:</h2> <pre><code>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") </code></pre> <h2>截图:</h2> <p><a href="https://i.stack.imgur.com/BnS4A.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BnS4A.png" alt="The speed is just ridiculous."/></a></p> <h2>预期解决方案:</h2> <p><em>不确定这个<a href="https://github.com/requests/requests/issues/2015" rel="nofollow noreferrer">Github Issue</a>是否已修复。</em></p> <ol> <li>最好是在requests模块中找到一个解决方案,但我愿意接受Python范围内的任何可以让我获得很好速度的答案。在</li> <li>我希望下载是分块的,因为我想通过progressbar查看进度。所以<code>shutil.copyfileobj(r.raw)</code>不是我要找的。在</li> <li>我确实尝试过使用多个线程,但这只是复杂的事情,并没有帮助。我认为问题在于将块写入缓冲区本身,而在线程之间分割任务并没有帮助。在</li> </ol> <h2>编辑:</h2> <p>根据建议,我尝试使用随机用户代理,如下所示:</p> ^{pr2}$ <p>并发送头为<code>r = requests.get(url,stream=True,headers=random_headers())</code>的请求</p> <p>然而,这没有什么不同。:(</p> <h2>编辑2:</h2> <p>用“<a href="http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_5mb.mp4" rel="nofollow noreferrer">http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_5mb.mp4</a>”中的示例视频进行了尝试。同样的问题依然存在。:/</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>你有没有试过用你的用户代理和其他Google可能需要的头来填充你的请求头,这样就不会把你标记为机器人,限制你的下载速度?在</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
得到媒体:缩略图url从rss源
7 回答
得到对数正态随机数给定log10均值和log10标准差
4 回答
得到工作,波斯特不
4 回答
得到左半积和右半积的绝对差最小的元素
9 回答
得到幻数错误?
9 回答
得到异常错误“线程中的异常-1(最有可能在解释器关闭期间引发)”,它使用Parami
7 回答
得到循环
7 回答
得到德语的语法变化
4 回答
得到我认为是好的结果,但还不够
3 回答
得到截断svd.transform()返回float16而不是float64
8 回答
得到所有不相交的集合的并集
8 回答
得到所有函数求值组合的矩阵
10 回答
得到扭曲延迟取消错误当使用刮痧时
3 回答
得到控制台.log使用Selenium python从Chrome输出一次,然后调用第二次为空
3 回答
得到操作系统环境通过NSSM运行Python
6 回答
得到数学方程中的表达式
2 回答
得到数据库结构属性
2 回答
得到整数的后三位
2 回答
得到整数的第n位精度
2 回答
得到最低落的reddit评论
10 回答