cv-cat / Spider_XHS

小红书爬虫,小红书笔记、主页、搜索爬取
772 stars 150 forks source link

下载视频的时候会报错,大佬遇到过这个问题吗 #3

Open yuchen21-web opened 10 months ago

yuchen21-web commented 10 months ago

这块代码 elif type == 'video': print(f"{name}开始下载, {media_url}") start_time = time.time() res = requests.get(media_url, stream=True) size = 0 chunk_size = 1024 * 1024 content_size = int(res.headers["content-length"]) with open(path + '/' + name + '.mp4', mode="wb") as f: for data in res.iter_content(chunk_size=chunk_size): f.write(data) size += len(data) # 已下载文件的大小

已完成的百分比

                    percentage = size / content_size
                    # 打印进度条
                    print(f'\r视频:%.2fMB\t' % (content_size / 1024 / 1024),
                          '下载进度:[%-50s%.2f%%]耗时:%.1fs' % ('>' * int(50 * percentage), percentage * 100, time.time() - start_time),
                          end='')
                print(f"{name}下载完成")

在下载某些视频的时候,会报这个错误。网上搜了好像也没啥解决方法

urllib3.exceptions.ProtocolError: ('Connection broken: IncompleteRead(10485760 bytes read, 280808 more expected)', IncompleteRead(10485760 bytes read, 280808 more expected))

cv-cat commented 8 months ago

已修复