サービス
サービスを探す
プロ人材を探す
仕事を探す
ブログを探す
import requests
from requests.exceptions import RequestException
response = requests.get(URL)
if response.status_code == 200:
with open(パス, 'wb') as fw:
for chunk in response.iter_content(chunk_size=100000):
fw.write(chunk)
print(f'{URL} のダウンロードが成功しました')
else:
print(f'{URL} のダウンロードに失敗しました (ステータスコード: {response.status_code})')
try:
response = requests.get(URL, timeout=10)
response.raise_for_status()
with open(パス, 'wb') as fw:
for chunk in response.iter_content(chunk_size=100000):
fw.write(chunk)
print(f'{URL} のダウンロードが成功しました')
except RequestException as e:
print(f'{URL} のダウンロード中にエラーが発生しました: {e}')