scrapy - 如何使用 requests 或 scrapy 从 opensubtitle.org 下载 zip 文件
问题描述
我有 zip 文件下载网址,链接如下: https ://dl.opensubtitles.org/en/download/sub/7790586/vrf-f5760bc3 。我使用所需的标头请求此 URL,但仍然无法下载 zip 文件。它被重定向到旧电影页面,否则下载不相关的 zip 文件内容。我知道有可用的 API,但我需要通过脚本来完成,而不是通过 API 或 selenium。
我尝试了 request 和 scrapy get 方法仍然无法下载正确的 zip 文件。
headers = {
"authority": "dl.opensubtitles.org","Connection": "keep-alive",
"user-agent":user_agent,
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3","accept-encoding": "gzip,deflate,br","accept-language": "en-IN,en-US;q=0.9,en;q=0.8","referer": movie_url,'upgrade-insecure-requests':'1'}
requests.get(url,headers=headers)
解决方案
with requests.get(url, stream=True) as res:
with open('test.zip', 'wb') as f:
for chunk in res.iter_content(chunk_size=1024): #you can also change the chunk size
if chunk: # filter out
f.write(chunk)
推荐阅读
- sql - 仅使用某些子项填充 JPA 填充子数组(一对多)
- java - 创建 jar 工件后 IntelliJ 没有 Main Mainifest 属性
- java - 获取 IllegalStateException:Session/EntityManager 在 session.evict() 上关闭
- azure - 是否可以通过 PowerShell 命令列出 extensionAttribute1 - extensionAttribute15?
- gradle - Gradle 配置集成
- math - 在计算 rust 时我有 `-inf`:什么是`-inf`?
- angular - OKTA redirect_uri 中的动态 URL
- keras - 将 hyperopt(或 hyperas)与 Keras 和 ImageDataGenerator "flow_from_directory" 一起使用
- android - 将项目迁移到 AndroidX 后,com.paymob.acceptsdk.PayActivity void androidx.appcompat.app.ActionBar 崩溃
- mysql - 如何将 2 行数据连接到 mysql 中单行的 1 列